user32: Scale the button size with screen resolution.
[wine.git] / dlls / wininet / internet.h
blobd400df00e4fb3afc154d417cc0fe0ecca76856a3
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 #include "wine/unicode.h"
27 #include "wine/list.h"
29 #include <time.h>
31 #include "winineti.h"
33 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
35 typedef struct {
36 WCHAR *name;
37 INTERNET_PORT port;
38 BOOL is_https;
39 struct sockaddr_storage addr;
40 int addr_len;
41 char addr_str[INET6_ADDRSTRLEN];
43 WCHAR *scheme_host_port;
44 const WCHAR *host_port;
45 const WCHAR *canon_host_port;
47 LONG ref;
49 DWORD security_flags;
50 const CERT_CHAIN_CONTEXT *cert_chain;
52 struct list entry;
53 struct list conn_pool;
54 } server_t;
56 void server_addref(server_t*) DECLSPEC_HIDDEN;
57 void server_release(server_t*) DECLSPEC_HIDDEN;
59 typedef enum {
60 COLLECT_TIMEOUT,
61 COLLECT_CONNECTIONS,
62 COLLECT_CLEANUP
63 } collect_type_t;
64 BOOL collect_connections(collect_type_t) DECLSPEC_HIDDEN;
66 /* used for netconnection.c stuff */
67 typedef struct
69 int socket;
70 BOOL secure;
71 BOOL is_blocking;
72 CtxtHandle ssl_ctx;
73 SecPkgContext_StreamSizes ssl_sizes;
74 server_t *server;
75 char *ssl_buf;
76 char *extra_buf;
77 size_t extra_len;
78 char *peek_msg;
79 char *peek_msg_mem;
80 size_t peek_len;
81 DWORD security_flags;
82 BOOL mask_errors;
84 BOOL keep_alive;
85 DWORD64 keep_until;
86 struct list pool_entry;
87 } netconn_t;
89 BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN;
90 void close_netconn(netconn_t *) DECLSPEC_HIDDEN;
92 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
94 return HeapAlloc(GetProcessHeap(), 0, len);
97 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
99 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
102 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
104 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
107 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
109 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
112 static inline BOOL heap_free(void *mem)
114 return HeapFree(GetProcessHeap(), 0, mem);
117 static inline LPWSTR heap_strdupW(LPCWSTR str)
119 LPWSTR ret = NULL;
121 if(str) {
122 DWORD size;
124 size = (strlenW(str)+1)*sizeof(WCHAR);
125 ret = heap_alloc(size);
126 if(ret)
127 memcpy(ret, str, size);
130 return ret;
133 static inline char *heap_strdupA(const char *str)
135 char *ret = NULL;
137 if(str) {
138 DWORD size = strlen(str)+1;
140 ret = heap_alloc(size);
141 if(ret)
142 memcpy(ret, str, size);
145 return ret;
148 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
150 LPWSTR ret;
151 UINT len;
153 if(!str)
154 return NULL;
156 for(len=0; len<max_len; len++)
157 if(str[len] == '\0')
158 break;
160 ret = heap_alloc(sizeof(WCHAR)*(len+1));
161 if(ret) {
162 memcpy(ret, str, sizeof(WCHAR)*len);
163 ret[len] = '\0';
166 return ret;
169 static inline WCHAR *heap_strndupAtoW(const char *str, int len_a, DWORD *len_w)
171 WCHAR *ret = NULL;
173 if(str) {
174 size_t len;
175 if(len_a < 0) len_a = strlen(str);
176 len = MultiByteToWideChar(CP_ACP, 0, str, len_a, NULL, 0);
177 ret = heap_alloc((len+1)*sizeof(WCHAR));
178 if(ret) {
179 MultiByteToWideChar(CP_ACP, 0, str, len_a, ret, len);
180 ret[len] = 0;
181 *len_w = len;
185 return ret;
188 static inline WCHAR *heap_strdupAtoW(const char *str)
190 LPWSTR ret = NULL;
192 if(str) {
193 DWORD len;
195 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
196 ret = heap_alloc(len*sizeof(WCHAR));
197 if(ret)
198 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
201 return ret;
204 static inline char *heap_strdupWtoA(LPCWSTR str)
206 char *ret = NULL;
208 if(str) {
209 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
210 ret = heap_alloc(size);
211 if(ret)
212 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
215 return ret;
218 typedef struct {
219 const WCHAR *str;
220 size_t len;
221 } substr_t;
223 static inline substr_t substr(const WCHAR *str, size_t len)
225 substr_t r = {str, len};
226 return r;
229 static inline substr_t substrz(const WCHAR *str)
231 return substr(str, strlenW(str));
234 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
236 dataA->dwFileAttributes = dataW->dwFileAttributes;
237 dataA->ftCreationTime = dataW->ftCreationTime;
238 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
239 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
240 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
241 dataA->nFileSizeLow = dataW->nFileSizeLow;
242 dataA->dwReserved0 = dataW->dwReserved0;
243 dataA->dwReserved1 = dataW->dwReserved1;
244 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
245 dataA->cFileName, sizeof(dataA->cFileName),
246 NULL, NULL);
247 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
248 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
249 NULL, NULL);
252 typedef enum
254 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
255 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
256 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
257 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
258 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
259 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
260 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
261 } WH_TYPE;
263 #define INET_OPENURL 0x0001
264 #define INET_CALLBACKW 0x0002
266 typedef struct
268 LONG ref;
269 HANDLE file_handle;
270 WCHAR *file_name;
271 WCHAR *url;
272 BOOL is_committed;
273 } req_file_t;
275 typedef struct _object_header_t object_header_t;
277 typedef struct {
278 void (*Destroy)(object_header_t*);
279 void (*CloseConnection)(object_header_t*);
280 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
281 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
282 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
283 DWORD (*ReadFileEx)(object_header_t*,void*,DWORD,DWORD*,DWORD,DWORD_PTR);
284 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
285 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
286 DWORD (*FindNextFileW)(object_header_t*,void*);
287 DWORD (*LockRequestFile)(object_header_t*,req_file_t**);
288 } object_vtbl_t;
290 #define INTERNET_HANDLE_IN_USE 1
292 struct _object_header_t
294 WH_TYPE htype;
295 const object_vtbl_t *vtbl;
296 HINTERNET hInternet;
297 BOOL valid_handle;
298 DWORD dwFlags;
299 DWORD_PTR dwContext;
300 DWORD dwError;
301 ULONG ErrorMask;
302 DWORD dwInternalFlags;
303 LONG refs;
304 INTERNET_STATUS_CALLBACK lpfnStatusCB;
305 struct list entry;
306 struct list children;
309 typedef struct
311 object_header_t hdr;
312 LPWSTR agent;
313 LPWSTR proxy;
314 LPWSTR proxyBypass;
315 LPWSTR proxyUsername;
316 LPWSTR proxyPassword;
317 DWORD accessType;
318 DWORD connect_timeout;
319 } appinfo_t;
321 typedef struct
323 object_header_t hdr;
324 appinfo_t *appInfo;
325 LPWSTR hostName; /* the final destination of the request */
326 LPWSTR userName;
327 LPWSTR password;
328 INTERNET_PORT hostPort; /* the final destination port of the request */
329 DWORD connect_timeout;
330 DWORD send_timeout;
331 DWORD receive_timeout;
332 } http_session_t;
334 #define HDR_ISREQUEST 0x0001
335 #define HDR_COMMADELIMITED 0x0002
336 #define HDR_SEMIDELIMITED 0x0004
338 typedef struct
340 LPWSTR lpszField;
341 LPWSTR lpszValue;
342 WORD wFlags;
343 WORD wCount;
344 } HTTPHEADERW, *LPHTTPHEADERW;
347 struct HttpAuthInfo;
349 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
351 typedef struct {
352 const data_stream_vtbl_t *vtbl;
353 } data_stream_t;
355 typedef struct {
356 data_stream_t data_stream;
357 DWORD content_length;
358 DWORD content_read;
359 } netconn_stream_t;
361 #define READ_BUFFER_SIZE 8192
363 typedef struct
365 object_header_t hdr;
366 http_session_t *session;
367 server_t *server;
368 server_t *proxy;
369 LPWSTR path;
370 LPWSTR verb;
371 netconn_t *netconn;
372 DWORD security_flags;
373 DWORD connect_timeout;
374 DWORD send_timeout;
375 DWORD receive_timeout;
376 LPWSTR version;
377 DWORD status_code;
378 LPWSTR statusText;
379 DWORD bytesToWrite;
380 DWORD bytesWritten;
382 CRITICAL_SECTION headers_section; /* section to protect the headers array */
383 HTTPHEADERW *custHeaders;
384 DWORD nCustHeaders;
386 FILETIME last_modified;
387 HANDLE hCacheFile;
388 req_file_t *req_file;
389 FILETIME expires;
390 struct HttpAuthInfo *authInfo;
391 struct HttpAuthInfo *proxyAuthInfo;
393 CRITICAL_SECTION read_section; /* section to protect the following fields */
394 DWORD contentLength; /* total number of bytes to be read */
395 BOOL read_gzip; /* are we reading in gzip mode? */
396 DWORD read_pos; /* current read position in read_buf */
397 DWORD read_size; /* valid data size in read_buf */
398 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
400 BOOL decoding;
401 data_stream_t *data_stream;
402 netconn_stream_t netconn_stream;
403 } http_request_t;
405 typedef struct task_header_t task_header_t;
406 typedef void (*async_task_proc_t)(task_header_t*);
408 struct task_header_t
410 async_task_proc_t proc;
411 object_header_t *hdr;
414 void *alloc_async_task(object_header_t*,async_task_proc_t,size_t) DECLSPEC_HIDDEN;
416 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
417 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
418 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
419 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
421 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
422 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
424 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
426 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
427 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
428 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
429 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
431 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
432 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
433 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
434 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
436 BOOL GetAddress(const WCHAR*,INTERNET_PORT,SOCKADDR*,int*,char*) DECLSPEC_HIDDEN;
438 DWORD get_cookie_header(const WCHAR*,const WCHAR*,WCHAR**) DECLSPEC_HIDDEN;
439 DWORD set_cookie(substr_t,substr_t,substr_t,substr_t,DWORD) DECLSPEC_HIDDEN;
441 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
442 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
443 DWORD INTERNET_AsyncCall(task_header_t*) DECLSPEC_HIDDEN;
444 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
446 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
447 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
448 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
449 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto) DECLSPEC_HIDDEN;
451 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
452 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
453 void NETCON_unload(void) DECLSPEC_HIDDEN;
454 DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN;
455 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
456 int *sent /* out */) DECLSPEC_HIDDEN;
457 DWORD NETCON_recv(netconn_t*,void*,size_t,BOOL,int*) DECLSPEC_HIDDEN;
458 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
459 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
460 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
461 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
462 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
463 int sock_send(int fd, const void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
464 int sock_recv(int fd, void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
466 server_t *get_server(substr_t,INTERNET_PORT,BOOL,BOOL) DECLSPEC_HIDDEN;
468 DWORD create_req_file(const WCHAR*,req_file_t**) DECLSPEC_HIDDEN;
469 void req_file_release(req_file_t*) DECLSPEC_HIDDEN;
471 static inline req_file_t *req_file_addref(req_file_t *req_file)
473 InterlockedIncrement(&req_file->ref);
474 return req_file;
477 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
478 void free_urlcache(void) DECLSPEC_HIDDEN;
479 void free_cookie(void) DECLSPEC_HIDDEN;
481 void init_winsock(void) DECLSPEC_HIDDEN;
483 #define MAX_REPLY_LEN 0x5B4
485 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
486 typedef struct
488 DWORD val;
489 const char* name;
490 } wininet_flag_info;
492 /* Undocumented security flags */
493 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
494 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
495 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
496 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
498 #define _SECURITY_ERROR_FLAGS_MASK \
499 (_SECURITY_FLAG_CERT_REV_FAILED \
500 |_SECURITY_FLAG_CERT_INVALID_CA \
501 |_SECURITY_FLAG_CERT_INVALID_CN \
502 |_SECURITY_FLAG_CERT_INVALID_DATE)
504 #endif /* _WINE_INTERNET_H_ */