wininet: Fixed InternetSetCookieExW return type and forward InternetSetCookieW to...
[wine/multimedia.git] / dlls / wininet / internet.h
blob45a13cad1c0a192f25a4ecda216f5fc5fefea020
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 #include "winineti.h"
52 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
54 #ifndef INET6_ADDRSTRLEN
55 #define INET6_ADDRSTRLEN 46
56 #endif
58 typedef struct {
59 WCHAR *name;
60 INTERNET_PORT port;
61 BOOL is_https;
62 struct sockaddr_storage addr;
63 socklen_t addr_len;
64 char addr_str[INET6_ADDRSTRLEN];
66 WCHAR *scheme_host_port;
67 const WCHAR *host_port;
68 const WCHAR *canon_host_port;
70 LONG ref;
72 DWORD security_flags;
73 const CERT_CHAIN_CONTEXT *cert_chain;
75 struct list entry;
76 struct list conn_pool;
77 } server_t;
79 void server_addref(server_t*) DECLSPEC_HIDDEN;
80 void server_release(server_t*) DECLSPEC_HIDDEN;
82 typedef enum {
83 COLLECT_TIMEOUT,
84 COLLECT_CONNECTIONS,
85 COLLECT_CLEANUP
86 } collect_type_t;
87 BOOL collect_connections(collect_type_t) DECLSPEC_HIDDEN;
89 /* used for netconnection.c stuff */
90 typedef struct
92 int socket;
93 BOOL secure;
94 CtxtHandle ssl_ctx;
95 SecPkgContext_StreamSizes ssl_sizes;
96 server_t *server;
97 char *ssl_buf;
98 char *extra_buf;
99 size_t extra_len;
100 char *peek_msg;
101 char *peek_msg_mem;
102 size_t peek_len;
103 DWORD security_flags;
104 BOOL mask_errors;
106 BOOL keep_alive;
107 DWORD64 keep_until;
108 struct list pool_entry;
109 } netconn_t;
111 BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN;
112 void close_netconn(netconn_t *) DECLSPEC_HIDDEN;
114 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
116 return HeapAlloc(GetProcessHeap(), 0, len);
119 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
121 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
124 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
126 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
129 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
131 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
134 static inline BOOL heap_free(void *mem)
136 return HeapFree(GetProcessHeap(), 0, mem);
139 static inline LPWSTR heap_strdupW(LPCWSTR str)
141 LPWSTR ret = NULL;
143 if(str) {
144 DWORD size;
146 size = (strlenW(str)+1)*sizeof(WCHAR);
147 ret = heap_alloc(size);
148 if(ret)
149 memcpy(ret, str, size);
152 return ret;
155 static inline char *heap_strdupA(const char *str)
157 char *ret = NULL;
159 if(str) {
160 DWORD size = strlen(str)+1;
162 ret = heap_alloc(size);
163 if(ret)
164 memcpy(ret, str, size);
167 return ret;
170 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
172 LPWSTR ret;
173 UINT len;
175 if(!str)
176 return NULL;
178 for(len=0; len<max_len; len++)
179 if(str[len] == '\0')
180 break;
182 ret = heap_alloc(sizeof(WCHAR)*(len+1));
183 if(ret) {
184 memcpy(ret, str, sizeof(WCHAR)*len);
185 ret[len] = '\0';
188 return ret;
191 static inline WCHAR *heap_strdupAtoW(const char *str)
193 LPWSTR ret = NULL;
195 if(str) {
196 DWORD len;
198 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
199 ret = heap_alloc(len*sizeof(WCHAR));
200 if(ret)
201 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
204 return ret;
207 static inline char *heap_strdupWtoA(LPCWSTR str)
209 char *ret = NULL;
211 if(str) {
212 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
213 ret = heap_alloc(size);
214 if(ret)
215 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
218 return ret;
221 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
223 dataA->dwFileAttributes = dataW->dwFileAttributes;
224 dataA->ftCreationTime = dataW->ftCreationTime;
225 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
226 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
227 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
228 dataA->nFileSizeLow = dataW->nFileSizeLow;
229 dataA->dwReserved0 = dataW->dwReserved0;
230 dataA->dwReserved1 = dataW->dwReserved1;
231 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
232 dataA->cFileName, sizeof(dataA->cFileName),
233 NULL, NULL);
234 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
235 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
236 NULL, NULL);
239 typedef enum
241 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
242 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
243 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
244 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
245 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
246 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
247 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
248 } WH_TYPE;
250 #define INET_OPENURL 0x0001
251 #define INET_CALLBACKW 0x0002
253 typedef struct
255 LONG ref;
256 HANDLE file_handle;
257 WCHAR *file_name;
258 BOOL is_committed;
259 } req_file_t;
261 typedef struct _object_header_t object_header_t;
263 typedef struct {
264 void (*Destroy)(object_header_t*);
265 void (*CloseConnection)(object_header_t*);
266 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
267 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
268 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
269 DWORD (*ReadFileEx)(object_header_t*,void*,DWORD,DWORD*,DWORD,DWORD_PTR);
270 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
271 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
272 DWORD (*FindNextFileW)(object_header_t*,void*);
273 DWORD (*LockRequestFile)(object_header_t*,req_file_t**);
274 } object_vtbl_t;
276 #define INTERNET_HANDLE_IN_USE 1
278 struct _object_header_t
280 WH_TYPE htype;
281 const object_vtbl_t *vtbl;
282 HINTERNET hInternet;
283 BOOL valid_handle;
284 DWORD dwFlags;
285 DWORD_PTR dwContext;
286 DWORD dwError;
287 ULONG ErrorMask;
288 DWORD dwInternalFlags;
289 LONG refs;
290 INTERNET_STATUS_CALLBACK lpfnStatusCB;
291 struct list entry;
292 struct list children;
295 typedef struct
297 object_header_t hdr;
298 LPWSTR agent;
299 LPWSTR proxy;
300 LPWSTR proxyBypass;
301 LPWSTR proxyUsername;
302 LPWSTR proxyPassword;
303 DWORD accessType;
304 DWORD connect_timeout;
305 } appinfo_t;
307 typedef struct
309 object_header_t hdr;
310 appinfo_t *appInfo;
311 LPWSTR hostName; /* the final destination of the request */
312 LPWSTR userName;
313 LPWSTR password;
314 INTERNET_PORT hostPort; /* the final destination port of the request */
315 DWORD connect_timeout;
316 DWORD send_timeout;
317 DWORD receive_timeout;
318 } http_session_t;
320 #define HDR_ISREQUEST 0x0001
321 #define HDR_COMMADELIMITED 0x0002
322 #define HDR_SEMIDELIMITED 0x0004
324 typedef struct
326 LPWSTR lpszField;
327 LPWSTR lpszValue;
328 WORD wFlags;
329 WORD wCount;
330 } HTTPHEADERW, *LPHTTPHEADERW;
333 struct HttpAuthInfo;
335 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
337 typedef struct {
338 const data_stream_vtbl_t *vtbl;
339 } data_stream_t;
341 typedef struct {
342 data_stream_t data_stream;
343 DWORD content_length;
344 DWORD content_read;
345 } netconn_stream_t;
347 #define READ_BUFFER_SIZE 8192
349 typedef struct
351 object_header_t hdr;
352 http_session_t *session;
353 server_t *server;
354 server_t *proxy;
355 LPWSTR path;
356 LPWSTR verb;
357 netconn_t *netconn;
358 DWORD security_flags;
359 DWORD connect_timeout;
360 DWORD send_timeout;
361 DWORD receive_timeout;
362 LPWSTR version;
363 DWORD status_code;
364 LPWSTR statusText;
365 DWORD bytesToWrite;
366 DWORD bytesWritten;
367 HTTPHEADERW *custHeaders;
368 DWORD nCustHeaders;
369 FILETIME last_modified;
370 HANDLE hCacheFile;
371 req_file_t *req_file;
372 FILETIME expires;
373 struct HttpAuthInfo *authInfo;
374 struct HttpAuthInfo *proxyAuthInfo;
376 CRITICAL_SECTION read_section; /* section to protect the following fields */
377 DWORD contentLength; /* total number of bytes to be read */
378 BOOL read_chunked; /* are we reading in chunked mode? */
379 BOOL read_gzip; /* are we reading in gzip mode? */
380 DWORD read_pos; /* current read position in read_buf */
381 DWORD read_size; /* valid data size in read_buf */
382 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
384 BOOL decoding;
385 data_stream_t *data_stream;
386 netconn_stream_t netconn_stream;
387 } http_request_t;
389 typedef struct task_header_t task_header_t;
390 typedef void (*async_task_proc_t)(task_header_t*);
392 struct task_header_t
394 async_task_proc_t proc;
395 object_header_t *hdr;
398 void *alloc_async_task(object_header_t*,async_task_proc_t,size_t) DECLSPEC_HIDDEN;
400 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
401 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
402 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
403 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
405 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
406 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
408 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
410 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
411 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
412 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
413 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
415 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
416 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
417 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
418 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
420 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
421 struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
423 DWORD get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
424 DWORD set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
426 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
427 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
428 DWORD INTERNET_AsyncCall(task_header_t*) DECLSPEC_HIDDEN;
429 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
430 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen) DECLSPEC_HIDDEN;
432 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
433 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
434 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
436 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
437 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
438 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
439 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
441 typedef enum {
442 BLOCKING_ALLOW,
443 BLOCKING_DISALLOW,
444 BLOCKING_WAITALL
445 } blocking_mode_t;
447 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
448 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
449 void NETCON_unload(void) DECLSPEC_HIDDEN;
450 DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN;
451 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
452 int *sent /* out */) DECLSPEC_HIDDEN;
453 DWORD NETCON_recv(netconn_t*,void*,size_t,blocking_mode_t,int*) DECLSPEC_HIDDEN;
454 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
455 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
456 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
457 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
458 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
459 int sock_get_error(int) DECLSPEC_HIDDEN;
460 int sock_send(int fd, const void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
461 int sock_recv(int fd, void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
463 server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL);
465 DWORD create_req_file(const WCHAR*,req_file_t**) DECLSPEC_HIDDEN;
466 void req_file_release(req_file_t*) DECLSPEC_HIDDEN;
468 static inline req_file_t *req_file_addref(req_file_t *req_file)
470 InterlockedIncrement(&req_file->ref);
471 return req_file;
474 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
475 void free_urlcache(void) DECLSPEC_HIDDEN;
476 void free_cookie(void) DECLSPEC_HIDDEN;
478 #define MAX_REPLY_LEN 0x5B4
480 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
481 typedef struct
483 DWORD val;
484 const char* name;
485 } wininet_flag_info;
487 /* Undocumented security flags */
488 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
489 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
490 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
491 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
493 #define _SECURITY_ERROR_FLAGS_MASK \
494 (_SECURITY_FLAG_CERT_REV_FAILED \
495 |_SECURITY_FLAG_CERT_INVALID_CA \
496 |_SECURITY_FLAG_CERT_INVALID_CN \
497 |_SECURITY_FLAG_CERT_INVALID_DATE)
499 #endif /* _WINE_INTERNET_H_ */