user32: Check for NULL pointer in ToUnicodeEx.
[wine/multimedia.git] / dlls / wininet / internet.h
blob925bfd0b0414c692313ea90796200ee2e913078f
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 CtxtHandle ssl_ctx;
72 SecPkgContext_StreamSizes ssl_sizes;
73 server_t *server;
74 char *ssl_buf;
75 char *extra_buf;
76 size_t extra_len;
77 char *peek_msg;
78 char *peek_msg_mem;
79 size_t peek_len;
80 DWORD security_flags;
81 BOOL mask_errors;
83 BOOL keep_alive;
84 DWORD64 keep_until;
85 struct list pool_entry;
86 } netconn_t;
88 BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN;
89 void close_netconn(netconn_t *) DECLSPEC_HIDDEN;
91 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
93 return HeapAlloc(GetProcessHeap(), 0, len);
96 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
98 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
101 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
103 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
106 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
108 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
111 static inline BOOL heap_free(void *mem)
113 return HeapFree(GetProcessHeap(), 0, mem);
116 static inline LPWSTR heap_strdupW(LPCWSTR str)
118 LPWSTR ret = NULL;
120 if(str) {
121 DWORD size;
123 size = (strlenW(str)+1)*sizeof(WCHAR);
124 ret = heap_alloc(size);
125 if(ret)
126 memcpy(ret, str, size);
129 return ret;
132 static inline char *heap_strdupA(const char *str)
134 char *ret = NULL;
136 if(str) {
137 DWORD size = strlen(str)+1;
139 ret = heap_alloc(size);
140 if(ret)
141 memcpy(ret, str, size);
144 return ret;
147 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
149 LPWSTR ret;
150 UINT len;
152 if(!str)
153 return NULL;
155 for(len=0; len<max_len; len++)
156 if(str[len] == '\0')
157 break;
159 ret = heap_alloc(sizeof(WCHAR)*(len+1));
160 if(ret) {
161 memcpy(ret, str, sizeof(WCHAR)*len);
162 ret[len] = '\0';
165 return ret;
168 static inline WCHAR *heap_strdupAtoW(const char *str)
170 LPWSTR ret = NULL;
172 if(str) {
173 DWORD len;
175 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
176 ret = heap_alloc(len*sizeof(WCHAR));
177 if(ret)
178 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
181 return ret;
184 static inline char *heap_strdupWtoA(LPCWSTR str)
186 char *ret = NULL;
188 if(str) {
189 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
190 ret = heap_alloc(size);
191 if(ret)
192 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
195 return ret;
198 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
200 dataA->dwFileAttributes = dataW->dwFileAttributes;
201 dataA->ftCreationTime = dataW->ftCreationTime;
202 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
203 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
204 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
205 dataA->nFileSizeLow = dataW->nFileSizeLow;
206 dataA->dwReserved0 = dataW->dwReserved0;
207 dataA->dwReserved1 = dataW->dwReserved1;
208 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
209 dataA->cFileName, sizeof(dataA->cFileName),
210 NULL, NULL);
211 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
212 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
213 NULL, NULL);
216 typedef enum
218 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
219 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
220 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
221 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
222 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
223 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
224 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
225 } WH_TYPE;
227 #define INET_OPENURL 0x0001
228 #define INET_CALLBACKW 0x0002
230 typedef struct
232 LONG ref;
233 HANDLE file_handle;
234 WCHAR *file_name;
235 BOOL is_committed;
236 } req_file_t;
238 typedef struct _object_header_t object_header_t;
240 typedef struct {
241 void (*Destroy)(object_header_t*);
242 void (*CloseConnection)(object_header_t*);
243 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
244 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
245 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
246 DWORD (*ReadFileEx)(object_header_t*,void*,DWORD,DWORD*,DWORD,DWORD_PTR);
247 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
248 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
249 DWORD (*FindNextFileW)(object_header_t*,void*);
250 DWORD (*LockRequestFile)(object_header_t*,req_file_t**);
251 } object_vtbl_t;
253 #define INTERNET_HANDLE_IN_USE 1
255 struct _object_header_t
257 WH_TYPE htype;
258 const object_vtbl_t *vtbl;
259 HINTERNET hInternet;
260 BOOL valid_handle;
261 DWORD dwFlags;
262 DWORD_PTR dwContext;
263 DWORD dwError;
264 ULONG ErrorMask;
265 DWORD dwInternalFlags;
266 LONG refs;
267 INTERNET_STATUS_CALLBACK lpfnStatusCB;
268 struct list entry;
269 struct list children;
272 typedef struct
274 object_header_t hdr;
275 LPWSTR agent;
276 LPWSTR proxy;
277 LPWSTR proxyBypass;
278 LPWSTR proxyUsername;
279 LPWSTR proxyPassword;
280 DWORD accessType;
281 DWORD connect_timeout;
282 } appinfo_t;
284 typedef struct
286 object_header_t hdr;
287 appinfo_t *appInfo;
288 LPWSTR hostName; /* the final destination of the request */
289 LPWSTR userName;
290 LPWSTR password;
291 INTERNET_PORT hostPort; /* the final destination port of the request */
292 DWORD connect_timeout;
293 DWORD send_timeout;
294 DWORD receive_timeout;
295 } http_session_t;
297 #define HDR_ISREQUEST 0x0001
298 #define HDR_COMMADELIMITED 0x0002
299 #define HDR_SEMIDELIMITED 0x0004
301 typedef struct
303 LPWSTR lpszField;
304 LPWSTR lpszValue;
305 WORD wFlags;
306 WORD wCount;
307 } HTTPHEADERW, *LPHTTPHEADERW;
310 struct HttpAuthInfo;
312 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
314 typedef struct {
315 const data_stream_vtbl_t *vtbl;
316 } data_stream_t;
318 typedef struct {
319 data_stream_t data_stream;
320 DWORD content_length;
321 DWORD content_read;
322 } netconn_stream_t;
324 #define READ_BUFFER_SIZE 8192
326 typedef struct
328 object_header_t hdr;
329 http_session_t *session;
330 server_t *server;
331 server_t *proxy;
332 LPWSTR path;
333 LPWSTR verb;
334 netconn_t *netconn;
335 DWORD security_flags;
336 DWORD connect_timeout;
337 DWORD send_timeout;
338 DWORD receive_timeout;
339 LPWSTR version;
340 DWORD status_code;
341 LPWSTR statusText;
342 DWORD bytesToWrite;
343 DWORD bytesWritten;
345 CRITICAL_SECTION headers_section; /* section to protect the headers array */
346 HTTPHEADERW *custHeaders;
347 DWORD nCustHeaders;
349 FILETIME last_modified;
350 HANDLE hCacheFile;
351 req_file_t *req_file;
352 FILETIME expires;
353 struct HttpAuthInfo *authInfo;
354 struct HttpAuthInfo *proxyAuthInfo;
356 CRITICAL_SECTION read_section; /* section to protect the following fields */
357 DWORD contentLength; /* total number of bytes to be read */
358 BOOL read_chunked; /* are we reading in chunked mode? */
359 BOOL read_gzip; /* are we reading in gzip mode? */
360 DWORD read_pos; /* current read position in read_buf */
361 DWORD read_size; /* valid data size in read_buf */
362 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
364 BOOL decoding;
365 data_stream_t *data_stream;
366 netconn_stream_t netconn_stream;
367 } http_request_t;
369 typedef struct task_header_t task_header_t;
370 typedef void (*async_task_proc_t)(task_header_t*);
372 struct task_header_t
374 async_task_proc_t proc;
375 object_header_t *hdr;
378 void *alloc_async_task(object_header_t*,async_task_proc_t,size_t) DECLSPEC_HIDDEN;
380 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
381 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
382 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
383 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
385 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
386 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
388 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
390 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
391 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
392 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
393 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
395 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
396 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
397 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
398 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
400 BOOL GetAddress(const WCHAR*,INTERNET_PORT,SOCKADDR*,int*,char*) DECLSPEC_HIDDEN;
402 DWORD get_cookie_header(const WCHAR*,const WCHAR*,WCHAR**) DECLSPEC_HIDDEN;
403 DWORD set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD) DECLSPEC_HIDDEN;
405 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
406 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
407 DWORD INTERNET_AsyncCall(task_header_t*) DECLSPEC_HIDDEN;
408 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
410 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
411 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
412 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
414 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
415 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
416 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
417 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
419 typedef enum {
420 BLOCKING_ALLOW,
421 BLOCKING_DISALLOW,
422 BLOCKING_WAITALL
423 } blocking_mode_t;
425 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
426 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
427 void NETCON_unload(void) DECLSPEC_HIDDEN;
428 DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN;
429 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
430 int *sent /* out */) DECLSPEC_HIDDEN;
431 DWORD NETCON_recv(netconn_t*,void*,size_t,blocking_mode_t,int*) DECLSPEC_HIDDEN;
432 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
433 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
434 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
435 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
436 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
437 int sock_send(int fd, const void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
438 int sock_recv(int fd, void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
440 server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL) DECLSPEC_HIDDEN;
442 DWORD create_req_file(const WCHAR*,req_file_t**) DECLSPEC_HIDDEN;
443 void req_file_release(req_file_t*) DECLSPEC_HIDDEN;
445 static inline req_file_t *req_file_addref(req_file_t *req_file)
447 InterlockedIncrement(&req_file->ref);
448 return req_file;
451 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
452 void free_urlcache(void) DECLSPEC_HIDDEN;
453 void free_cookie(void) DECLSPEC_HIDDEN;
455 void init_winsock(void) DECLSPEC_HIDDEN;
457 #define MAX_REPLY_LEN 0x5B4
459 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
460 typedef struct
462 DWORD val;
463 const char* name;
464 } wininet_flag_info;
466 /* Undocumented security flags */
467 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
468 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
469 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
470 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
472 #define _SECURITY_ERROR_FLAGS_MASK \
473 (_SECURITY_FLAG_CERT_REV_FAILED \
474 |_SECURITY_FLAG_CERT_INVALID_CA \
475 |_SECURITY_FLAG_CERT_INVALID_CN \
476 |_SECURITY_FLAG_CERT_INVALID_DATE)
478 #endif /* _WINE_INTERNET_H_ */