winex11: Always create XIC preedit and status attributes.
[wine.git] / dlls / wininet / internet.h
blobd9598d18eb58443a6cc2f19cdfe778dc249bd687
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/list.h"
28 #include <time.h>
30 #include "winineti.h"
32 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
34 typedef struct {
35 WCHAR *name;
36 INTERNET_PORT port;
37 BOOL is_https;
38 struct sockaddr_storage addr;
39 int addr_len;
40 char addr_str[INET6_ADDRSTRLEN];
42 WCHAR *scheme_host_port;
43 const WCHAR *host_port;
44 const WCHAR *canon_host_port;
46 LONG ref;
48 DWORD security_flags;
49 const CERT_CHAIN_CONTEXT *cert_chain;
51 struct list entry;
52 struct list conn_pool;
53 } server_t;
55 void server_addref(server_t*) DECLSPEC_HIDDEN;
56 void server_release(server_t*) DECLSPEC_HIDDEN;
58 typedef enum {
59 COLLECT_TIMEOUT,
60 COLLECT_CONNECTIONS,
61 COLLECT_CLEANUP
62 } collect_type_t;
63 BOOL collect_connections(collect_type_t) DECLSPEC_HIDDEN;
65 /* used for netconnection.c stuff */
66 typedef struct
68 int socket;
69 BOOL secure;
70 BOOL is_blocking;
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 WCHAR *strndupW(const WCHAR *str, UINT max_len)
93 LPWSTR ret;
94 UINT len;
96 if(!str)
97 return NULL;
99 for(len=0; len<max_len; len++)
100 if(str[len] == '\0')
101 break;
103 ret = malloc(sizeof(WCHAR) * (len + 1));
104 if(ret) {
105 memcpy(ret, str, sizeof(WCHAR)*len);
106 ret[len] = '\0';
109 return ret;
112 static inline WCHAR *strndupAtoW(const char *str, int len_a, DWORD *len_w)
114 WCHAR *ret = NULL;
116 if(str) {
117 size_t len;
118 if(len_a < 0)
119 len_a = strlen(str);
120 else if(len_a > 0)
121 len_a = strnlen(str, len_a);
122 len = MultiByteToWideChar(CP_ACP, 0, str, len_a, NULL, 0);
123 ret = malloc((len + 1) * sizeof(WCHAR));
124 if(ret) {
125 MultiByteToWideChar(CP_ACP, 0, str, len_a, ret, len);
126 ret[len] = 0;
127 *len_w = len;
131 return ret;
134 static inline WCHAR *strdupAtoW(const char *str)
136 LPWSTR ret = NULL;
138 if(str) {
139 DWORD len;
141 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
142 ret = malloc(len * sizeof(WCHAR));
143 if(ret)
144 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
147 return ret;
150 static inline char *strdupWtoA(const WCHAR *str)
152 char *ret = NULL;
154 if(str) {
155 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
156 ret = malloc(size);
157 if(ret)
158 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
161 return ret;
164 typedef struct {
165 const WCHAR *str;
166 size_t len;
167 } substr_t;
169 static inline substr_t substr(const WCHAR *str, size_t len)
171 substr_t r = {str, len};
172 return r;
175 static inline substr_t substrz(const WCHAR *str)
177 return substr(str, lstrlenW(str));
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
214 LONG ref;
215 HANDLE file_handle;
216 WCHAR *file_name;
217 WCHAR *url;
218 BOOL is_committed;
219 } req_file_t;
221 typedef struct _object_header_t object_header_t;
223 typedef struct {
224 void (*Destroy)(object_header_t*);
225 void (*CloseConnection)(object_header_t*);
226 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
227 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
228 DWORD (*SetFilePointer)(object_header_t*,LONG,DWORD);
229 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*,DWORD,DWORD_PTR);
230 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
231 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
232 DWORD (*FindNextFileW)(object_header_t*,void*);
233 DWORD (*LockRequestFile)(object_header_t*,req_file_t**);
234 } object_vtbl_t;
236 #define INTERNET_HANDLE_IN_USE 1
238 struct _object_header_t
240 WH_TYPE htype;
241 const object_vtbl_t *vtbl;
242 HINTERNET hInternet;
243 BOOL valid_handle;
244 DWORD dwFlags;
245 DWORD_PTR dwContext;
246 DWORD dwError;
247 ULONG ErrorMask;
248 DWORD dwInternalFlags;
249 LONG refs;
250 BOOL decoding;
251 INTERNET_STATUS_CALLBACK lpfnStatusCB;
252 struct list entry;
253 struct list children;
256 typedef struct
258 object_header_t hdr;
259 LPWSTR agent;
260 LPWSTR proxy;
261 LPWSTR proxyBypass;
262 LPWSTR proxyUsername;
263 LPWSTR proxyPassword;
264 DWORD accessType;
265 DWORD connect_timeout;
266 } appinfo_t;
268 typedef struct
270 object_header_t hdr;
271 appinfo_t *appInfo;
272 LPWSTR hostName; /* the final destination of the request */
273 LPWSTR userName;
274 LPWSTR password;
275 INTERNET_PORT hostPort; /* the final destination port of the request */
276 DWORD connect_timeout;
277 DWORD send_timeout;
278 DWORD receive_timeout;
279 } http_session_t;
281 #define HDR_ISREQUEST 0x0001
282 #define HDR_COMMADELIMITED 0x0002
283 #define HDR_SEMIDELIMITED 0x0004
285 typedef struct
287 LPWSTR lpszField;
288 LPWSTR lpszValue;
289 WORD wFlags;
290 WORD wCount;
291 } HTTPHEADERW, *LPHTTPHEADERW;
294 struct HttpAuthInfo;
296 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
298 typedef struct {
299 const data_stream_vtbl_t *vtbl;
300 } data_stream_t;
302 typedef struct {
303 data_stream_t data_stream;
304 ULONGLONG content_length;
305 ULONGLONG content_read;
306 } netconn_stream_t;
308 #define READ_BUFFER_SIZE 8192
310 typedef struct
312 object_header_t hdr;
313 http_session_t *session;
314 server_t *server;
315 server_t *proxy;
316 LPWSTR path;
317 LPWSTR verb;
318 netconn_t *netconn;
319 DWORD security_flags;
320 DWORD connect_timeout;
321 DWORD send_timeout;
322 DWORD receive_timeout;
323 LPWSTR version;
324 DWORD status_code;
325 LPWSTR statusText;
326 DWORD bytesToWrite;
327 DWORD bytesWritten;
328 BOOL clear_auth; /* Flag to clear the password field on the authorization dialog */
330 CRITICAL_SECTION headers_section; /* section to protect the headers array */
331 HTTPHEADERW *custHeaders;
332 DWORD nCustHeaders;
334 FILETIME last_modified;
335 HANDLE hCacheFile;
336 ULONGLONG cache_size; /* size of cached data */
337 req_file_t *req_file;
338 FILETIME expires;
339 struct HttpAuthInfo *authInfo;
340 struct HttpAuthInfo *proxyAuthInfo;
342 CRITICAL_SECTION read_section; /* section to protect the following fields */
343 ULONGLONG contentLength; /* total number of bytes to be read */
344 ULONGLONG content_pos; /* content read position */
345 BOOL read_gzip; /* are we reading in gzip mode? */
346 DWORD read_pos; /* current read position in read_buf */
347 DWORD read_size; /* valid data size in read_buf */
348 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
350 data_stream_t *data_stream;
351 netconn_stream_t netconn_stream;
352 } http_request_t;
354 typedef struct task_header_t task_header_t;
355 typedef void (*async_task_proc_t)(task_header_t*);
357 struct task_header_t
359 async_task_proc_t proc;
360 object_header_t *hdr;
363 void *alloc_async_task(object_header_t*,async_task_proc_t,size_t) DECLSPEC_HIDDEN;
365 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
366 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
367 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
368 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
370 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
371 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
373 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
375 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
376 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
377 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
378 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
380 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
381 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
382 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
383 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
385 BOOL GetAddress(const WCHAR*,INTERNET_PORT,SOCKADDR*,int*,char*) DECLSPEC_HIDDEN;
387 DWORD get_cookie_header(const WCHAR*,const WCHAR*,WCHAR**) DECLSPEC_HIDDEN;
388 DWORD set_cookie(substr_t,substr_t,substr_t,substr_t,DWORD) DECLSPEC_HIDDEN;
390 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
391 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
392 DWORD INTERNET_AsyncCall(task_header_t*) DECLSPEC_HIDDEN;
393 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
395 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
396 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
397 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
398 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto) DECLSPEC_HIDDEN;
400 DWORD create_netconn(server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
401 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
402 void NETCON_unload(void) DECLSPEC_HIDDEN;
403 DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN;
404 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
405 int *sent /* out */) DECLSPEC_HIDDEN;
406 DWORD NETCON_recv(netconn_t*,void*,size_t,BOOL,int*) DECLSPEC_HIDDEN;
407 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
408 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
409 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
410 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
411 int sock_send(int fd, const void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
412 int sock_recv(int fd, void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
414 server_t *get_server(substr_t,INTERNET_PORT,BOOL,BOOL) DECLSPEC_HIDDEN;
416 DWORD create_req_file(const WCHAR*,req_file_t**) DECLSPEC_HIDDEN;
417 void req_file_release(req_file_t*) DECLSPEC_HIDDEN;
419 static inline req_file_t *req_file_addref(req_file_t *req_file)
421 InterlockedIncrement(&req_file->ref);
422 return req_file;
425 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
426 void free_urlcache(void) DECLSPEC_HIDDEN;
427 void free_cookie(void) DECLSPEC_HIDDEN;
428 void free_authorization_cache(void) DECLSPEC_HIDDEN;
430 void init_winsock(void) DECLSPEC_HIDDEN;
432 #define MAX_REPLY_LEN 0x1000
434 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
435 typedef struct
437 DWORD val;
438 const char* name;
439 } wininet_flag_info;
441 /* Undocumented security flags */
442 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
443 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
444 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
445 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
447 #define _SECURITY_ERROR_FLAGS_MASK \
448 (_SECURITY_FLAG_CERT_REV_FAILED \
449 |_SECURITY_FLAG_CERT_INVALID_CA \
450 |_SECURITY_FLAG_CERT_INVALID_CN \
451 |_SECURITY_FLAG_CERT_INVALID_DATE)
453 #endif /* _WINE_INTERNET_H_ */