shell32: Remove redundant loop to count already known value.
[wine/multimedia.git] / dlls / wininet / internet.h
bloba7af629f69dbece0975c1c85014bd33c75886e35
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
6 * Ulrich Czekalla
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.
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.
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
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
30 #include "wine/unicode.h"
31 #include "wine/list.h"
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
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
50 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
52 #ifndef INET6_ADDRSTRLEN
53 #define INET6_ADDRSTRLEN 46
54 #endif
56 typedef struct {
57 WCHAR *name;
58 INTERNET_PORT port;
59 struct sockaddr_storage addr;
60 socklen_t addr_len;
61 char addr_str[INET6_ADDRSTRLEN];
63 LONG ref;
64 DWORD64 keep_until;
66 struct list entry;
67 struct list conn_pool;
68 } server_t;
70 void server_addref(server_t*) DECLSPEC_HIDDEN;
71 void server_release(server_t*) DECLSPEC_HIDDEN;
72 BOOL collect_connections(BOOL) DECLSPEC_HIDDEN;
74 /* used for netconnection.c stuff */
75 typedef struct
77 BOOL useSSL;
78 int socketFD;
79 void *ssl_s;
80 server_t *server;
81 DWORD security_flags;
83 BOOL keep_alive;
84 DWORD64 keep_until;
85 struct list pool_entry;
86 } netconn_t;
88 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
90 return HeapAlloc(GetProcessHeap(), 0, len);
93 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
95 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
98 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
100 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
103 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
105 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
108 static inline BOOL heap_free(void *mem)
110 return HeapFree(GetProcessHeap(), 0, mem);
113 static inline LPWSTR heap_strdupW(LPCWSTR str)
115 LPWSTR ret = NULL;
117 if(str) {
118 DWORD size;
120 size = (strlenW(str)+1)*sizeof(WCHAR);
121 ret = heap_alloc(size);
122 if(ret)
123 memcpy(ret, str, size);
126 return ret;
129 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
131 LPWSTR ret;
132 UINT len;
134 if(!str)
135 return NULL;
137 for(len=0; len<max_len; len++)
138 if(str[len] == '\0')
139 break;
141 ret = heap_alloc(sizeof(WCHAR)*(len+1));
142 if(ret) {
143 memcpy(ret, str, sizeof(WCHAR)*len);
144 ret[len] = '\0';
147 return ret;
150 static inline WCHAR *heap_strdupAtoW(const char *str)
152 LPWSTR ret = NULL;
154 if(str) {
155 DWORD len;
157 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
158 ret = heap_alloc(len*sizeof(WCHAR));
159 if(ret)
160 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
163 return ret;
166 static inline char *heap_strdupWtoA(LPCWSTR str)
168 char *ret = NULL;
170 if(str) {
171 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
172 ret = heap_alloc(size);
173 if(ret)
174 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
177 return ret;
180 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
182 dataA->dwFileAttributes = dataW->dwFileAttributes;
183 dataA->ftCreationTime = dataW->ftCreationTime;
184 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
185 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
186 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
187 dataA->nFileSizeLow = dataW->nFileSizeLow;
188 dataA->dwReserved0 = dataW->dwReserved0;
189 dataA->dwReserved1 = dataW->dwReserved1;
190 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
191 dataA->cFileName, sizeof(dataA->cFileName),
192 NULL, NULL);
193 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
194 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
195 NULL, NULL);
198 typedef enum
200 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
201 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
202 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
203 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
204 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
205 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
206 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
207 } WH_TYPE;
209 #define INET_OPENURL 0x0001
210 #define INET_CALLBACKW 0x0002
212 typedef struct _object_header_t object_header_t;
214 typedef struct {
215 void (*Destroy)(object_header_t*);
216 void (*CloseConnection)(object_header_t*);
217 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
218 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
219 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
220 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
221 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
222 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
223 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
224 DWORD (*FindNextFileW)(object_header_t*,void*);
225 } object_vtbl_t;
227 #define INTERNET_HANDLE_IN_USE 1
229 struct _object_header_t
231 WH_TYPE htype;
232 const object_vtbl_t *vtbl;
233 HINTERNET hInternet;
234 BOOL valid_handle;
235 DWORD dwFlags;
236 DWORD_PTR dwContext;
237 DWORD dwError;
238 ULONG ErrorMask;
239 DWORD dwInternalFlags;
240 LONG refs;
241 INTERNET_STATUS_CALLBACK lpfnStatusCB;
242 struct list entry;
243 struct list children;
247 typedef struct
249 object_header_t hdr;
250 LPWSTR agent;
251 LPWSTR proxy;
252 LPWSTR proxyBypass;
253 LPWSTR proxyUsername;
254 LPWSTR proxyPassword;
255 DWORD accessType;
256 } appinfo_t;
258 typedef struct
260 object_header_t hdr;
261 appinfo_t *appInfo;
262 LPWSTR hostName; /* the final destination of the request */
263 LPWSTR serverName; /* the name of the server we directly connect to */
264 LPWSTR userName;
265 LPWSTR password;
266 INTERNET_PORT hostPort; /* the final destination port of the request */
267 INTERNET_PORT serverPort; /* the port of the server we directly connect to */
268 } http_session_t;
270 #define HDR_ISREQUEST 0x0001
271 #define HDR_COMMADELIMITED 0x0002
272 #define HDR_SEMIDELIMITED 0x0004
274 typedef struct
276 LPWSTR lpszField;
277 LPWSTR lpszValue;
278 WORD wFlags;
279 WORD wCount;
280 } HTTPHEADERW, *LPHTTPHEADERW;
283 struct HttpAuthInfo;
285 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
287 typedef struct {
288 const data_stream_vtbl_t *vtbl;
289 } data_stream_t;
291 typedef struct {
292 data_stream_t data_stream;
293 DWORD content_length;
294 DWORD content_read;
295 } netconn_stream_t;
297 #define READ_BUFFER_SIZE 8192
299 typedef struct
301 object_header_t hdr;
302 http_session_t *session;
303 LPWSTR path;
304 LPWSTR verb;
305 LPWSTR rawHeaders;
306 netconn_t *netconn;
307 DWORD security_flags;
308 LPWSTR version;
309 LPWSTR statusText;
310 DWORD bytesToWrite;
311 DWORD bytesWritten;
312 HTTPHEADERW *custHeaders;
313 DWORD nCustHeaders;
314 FILETIME last_modified;
315 HANDLE hCacheFile;
316 LPWSTR cacheFile;
317 FILETIME expires;
318 struct HttpAuthInfo *authInfo;
319 struct HttpAuthInfo *proxyAuthInfo;
321 CRITICAL_SECTION read_section; /* section to protect the following fields */
322 DWORD contentLength; /* total number of bytes to be read */
323 BOOL read_chunked; /* are we reading in chunked mode? */
324 BOOL read_gzip; /* are we reading in gzip mode? */
325 DWORD read_pos; /* current read position in read_buf */
326 DWORD read_size; /* valid data size in read_buf */
327 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
329 BOOL decoding;
330 data_stream_t *data_stream;
331 netconn_stream_t netconn_stream;
332 } http_request_t;
336 struct WORKREQ_FTPPUTFILEW
338 LPWSTR lpszLocalFile;
339 LPWSTR lpszNewRemoteFile;
340 DWORD dwFlags;
341 DWORD_PTR dwContext;
344 struct WORKREQ_FTPSETCURRENTDIRECTORYW
346 LPWSTR lpszDirectory;
349 struct WORKREQ_FTPCREATEDIRECTORYW
351 LPWSTR lpszDirectory;
354 struct WORKREQ_FTPFINDFIRSTFILEW
356 LPWSTR lpszSearchFile;
357 LPWIN32_FIND_DATAW lpFindFileData;
358 DWORD dwFlags;
359 DWORD_PTR dwContext;
362 struct WORKREQ_FTPGETCURRENTDIRECTORYW
364 LPWSTR lpszDirectory;
365 DWORD *lpdwDirectory;
368 struct WORKREQ_FTPOPENFILEW
370 LPWSTR lpszFilename;
371 DWORD dwAccess;
372 DWORD dwFlags;
373 DWORD_PTR dwContext;
376 struct WORKREQ_FTPGETFILEW
378 LPWSTR lpszRemoteFile;
379 LPWSTR lpszNewFile;
380 BOOL fFailIfExists;
381 DWORD dwLocalFlagsAttribute;
382 DWORD dwFlags;
383 DWORD_PTR dwContext;
386 struct WORKREQ_FTPDELETEFILEW
388 LPWSTR lpszFilename;
391 struct WORKREQ_FTPREMOVEDIRECTORYW
393 LPWSTR lpszDirectory;
396 struct WORKREQ_FTPRENAMEFILEW
398 LPWSTR lpszSrcFile;
399 LPWSTR lpszDestFile;
402 struct WORKREQ_FTPFINDNEXTW
404 LPWIN32_FIND_DATAW lpFindFileData;
407 struct WORKREQ_HTTPSENDREQUESTW
409 LPWSTR lpszHeader;
410 DWORD dwHeaderLength;
411 LPVOID lpOptional;
412 DWORD dwOptionalLength;
413 DWORD dwContentLength;
414 BOOL bEndRequest;
417 struct WORKREQ_HTTPENDREQUESTW
419 DWORD dwFlags;
420 DWORD_PTR dwContext;
423 struct WORKREQ_SENDCALLBACK
425 DWORD_PTR dwContext;
426 DWORD dwInternetStatus;
427 LPVOID lpvStatusInfo;
428 DWORD dwStatusInfoLength;
431 struct WORKREQ_INTERNETOPENURLW
433 HINTERNET hInternet;
434 LPWSTR lpszUrl;
435 LPWSTR lpszHeaders;
436 DWORD dwHeadersLength;
437 DWORD dwFlags;
438 DWORD_PTR dwContext;
441 struct WORKREQ_INTERNETREADFILEEXA
443 LPINTERNET_BUFFERSA lpBuffersOut;
446 struct WORKREQ_INTERNETREADFILEEXW
448 LPINTERNET_BUFFERSW lpBuffersOut;
451 typedef struct WORKREQ
453 void (*asyncproc)(struct WORKREQ*);
454 object_header_t *hdr;
456 union {
457 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
458 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
459 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
460 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
461 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
462 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
463 struct WORKREQ_FTPGETFILEW FtpGetFileW;
464 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
465 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
466 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
467 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
468 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
469 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
470 struct WORKREQ_SENDCALLBACK SendCallback;
471 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
472 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
473 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
474 } u;
476 } WORKREQUEST, *LPWORKREQUEST;
478 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
479 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
480 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
481 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
483 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL ) DECLSPEC_HIDDEN;
485 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
487 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
488 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
489 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
490 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
492 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
493 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
494 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
495 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
497 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
498 struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
500 BOOL get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
501 BOOL set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
503 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
504 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
505 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest) DECLSPEC_HIDDEN;
506 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
507 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen) DECLSPEC_HIDDEN;
509 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
510 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
511 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
513 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
514 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
515 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
516 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
518 DWORD create_netconn(BOOL,server_t*,DWORD,netconn_t**) DECLSPEC_HIDDEN;
519 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
520 void NETCON_unload(void) DECLSPEC_HIDDEN;
521 DWORD NETCON_secure_connect(netconn_t *connection, LPWSTR hostname) DECLSPEC_HIDDEN;
522 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
523 int *sent /* out */) DECLSPEC_HIDDEN;
524 DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, int flags,
525 int *recvd /* out */) DECLSPEC_HIDDEN;
526 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
527 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
528 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
529 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
530 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, int value) DECLSPEC_HIDDEN;
531 int sock_get_error(int) DECLSPEC_HIDDEN;
533 extern void URLCacheContainers_CreateDefaults(void) DECLSPEC_HIDDEN;
534 extern void URLCacheContainers_DeleteAll(void) DECLSPEC_HIDDEN;
536 #define MAX_REPLY_LEN 0x5B4
538 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
539 typedef struct
541 DWORD val;
542 const char* name;
543 } wininet_flag_info;
545 #endif /* _WINE_INTERNET_H_ */