winhttp: Support WINHTTP_OPTION_WEB_SOCKET_KEEPALIVE_INTERVAL.
[wine.git] / dlls / winhttp / winhttp_private.h
blob52f9eb171ee4e5b3b9797e500beacb986d2cca26
1 /*
2 * Copyright 2008 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef _WINE_WINHTTP_PRIVATE_H_
20 #define _WINE_WINHTTP_PRIVATE_H_
22 #include "ole2.h"
23 #include "sspi.h"
24 #include "wincrypt.h"
26 #include "wine/list.h"
28 #define WINHTTP_HANDLE_TYPE_SOCKET 4
30 struct object_header;
31 struct object_vtbl
33 void (*handle_closing) ( struct object_header * );
34 void (*destroy)( struct object_header * );
35 BOOL (*query_option)( struct object_header *, DWORD, void *, DWORD * );
36 BOOL (*set_option)( struct object_header *, DWORD, void *, DWORD );
39 struct object_header
41 DWORD type;
42 HINTERNET handle;
43 const struct object_vtbl *vtbl;
44 DWORD flags;
45 DWORD disable_flags;
46 DWORD logon_policy;
47 DWORD redirect_policy;
48 DWORD error;
49 DWORD_PTR context;
50 LONG refs;
51 WINHTTP_STATUS_CALLBACK callback;
52 DWORD notify_mask;
53 LONG recursion_count;
54 struct list entry;
55 volatile LONG pending_sends;
56 volatile LONG pending_receives;
59 struct hostdata
61 struct list entry;
62 LONG ref;
63 WCHAR *hostname;
64 INTERNET_PORT port;
65 BOOL secure;
66 struct list connections;
69 struct session
71 struct object_header hdr;
72 CRITICAL_SECTION cs;
73 WCHAR *agent;
74 DWORD access;
75 int resolve_timeout;
76 int connect_timeout;
77 int send_timeout;
78 int receive_timeout;
79 int receive_response_timeout;
80 WCHAR *proxy_server;
81 WCHAR *proxy_bypass;
82 WCHAR *proxy_username;
83 WCHAR *proxy_password;
84 struct list cookie_cache;
85 HANDLE unload_event;
86 DWORD secure_protocols;
87 DWORD passport_flags;
90 struct connect
92 struct object_header hdr;
93 struct session *session;
94 WCHAR *hostname; /* final destination of the request */
95 WCHAR *servername; /* name of the server we directly connect to */
96 WCHAR *username;
97 WCHAR *password;
98 INTERNET_PORT hostport;
99 INTERNET_PORT serverport;
100 struct sockaddr_storage sockaddr;
101 BOOL resolved;
104 struct netconn
106 struct list entry;
107 int socket;
108 struct sockaddr_storage sockaddr;
109 BOOL secure; /* SSL active on connection? */
110 struct hostdata *host;
111 ULONGLONG keep_until;
112 CtxtHandle ssl_ctx;
113 SecPkgContext_StreamSizes ssl_sizes;
114 char *ssl_read_buf, *ssl_write_buf;
115 char *extra_buf;
116 size_t extra_len;
117 char *peek_msg;
118 char *peek_msg_mem;
119 size_t peek_len;
120 HANDLE port;
123 struct header
125 WCHAR *field;
126 WCHAR *value;
127 BOOL is_request; /* part of request headers? */
130 enum auth_target
132 TARGET_INVALID = -1,
133 TARGET_SERVER,
134 TARGET_PROXY,
135 TARGET_MAX
138 enum auth_scheme
140 SCHEME_INVALID = -1,
141 SCHEME_BASIC,
142 SCHEME_NTLM,
143 SCHEME_PASSPORT,
144 SCHEME_DIGEST,
145 SCHEME_NEGOTIATE,
146 SCHEME_MAX
149 struct authinfo
151 enum auth_scheme scheme;
152 CredHandle cred;
153 CtxtHandle ctx;
154 TimeStamp exp;
155 ULONG attr;
156 ULONG max_token;
157 char *data;
158 unsigned int data_len;
159 BOOL finished; /* finished authenticating */
162 struct queue
164 SRWLOCK lock;
165 struct list queued_tasks;
166 BOOL callback_running;
169 enum request_flags
171 REQUEST_FLAG_WEBSOCKET_UPGRADE = 0x01,
174 struct request
176 struct object_header hdr;
177 struct connect *connect;
178 enum request_flags flags;
179 WCHAR *verb;
180 WCHAR *path;
181 WCHAR *version;
182 WCHAR *raw_headers;
183 void *optional;
184 DWORD optional_len;
185 struct netconn *netconn;
186 DWORD security_flags;
187 BOOL check_revocation;
188 const CERT_CONTEXT *server_cert;
189 const CERT_CONTEXT *client_cert;
190 CredHandle cred_handle;
191 BOOL cred_handle_initialized;
192 int resolve_timeout;
193 int connect_timeout;
194 int send_timeout;
195 int receive_timeout;
196 int receive_response_timeout;
197 DWORD max_redirects;
198 DWORD redirect_count; /* total number of redirects during this request */
199 WCHAR *status_text;
200 DWORD content_length; /* total number of bytes to be read */
201 DWORD content_read; /* bytes read so far */
202 BOOL read_chunked; /* are we reading in chunked mode? */
203 BOOL read_chunked_eof; /* end of stream in chunked mode */
204 BOOL read_chunked_size; /* chunk size remaining */
205 DWORD read_pos; /* current read position in read_buf */
206 DWORD read_size; /* valid data size in read_buf */
207 char read_buf[8192]; /* buffer for already read but not returned data */
208 struct header *headers;
209 DWORD num_headers;
210 struct authinfo *authinfo;
211 struct authinfo *proxy_authinfo;
212 struct queue queue;
213 struct
215 WCHAR *username;
216 WCHAR *password;
217 } creds[TARGET_MAX][SCHEME_MAX];
220 enum socket_state
222 SOCKET_STATE_OPEN = 0,
223 SOCKET_STATE_SHUTDOWN = 1,
224 SOCKET_STATE_CLOSED = 2,
227 /* rfc6455 */
228 enum socket_opcode
230 SOCKET_OPCODE_CONTINUE = 0x00,
231 SOCKET_OPCODE_TEXT = 0x01,
232 SOCKET_OPCODE_BINARY = 0x02,
233 SOCKET_OPCODE_RESERVED3 = 0x03,
234 SOCKET_OPCODE_RESERVED4 = 0x04,
235 SOCKET_OPCODE_RESERVED5 = 0x05,
236 SOCKET_OPCODE_RESERVED6 = 0x06,
237 SOCKET_OPCODE_RESERVED7 = 0x07,
238 SOCKET_OPCODE_CLOSE = 0x08,
239 SOCKET_OPCODE_PING = 0x09,
240 SOCKET_OPCODE_PONG = 0x0a,
241 SOCKET_OPCODE_INVALID = 0xff,
244 enum fragment_type
246 SOCKET_FRAGMENT_NONE,
247 SOCKET_FRAGMENT_BINARY,
248 SOCKET_FRAGMENT_UTF8,
251 struct socket
253 struct object_header hdr;
254 struct request *request;
255 int keepalive_interval;
256 enum socket_state state;
257 struct queue send_q;
258 struct queue recv_q;
259 enum socket_opcode opcode;
260 DWORD read_size;
261 char mask[4];
262 unsigned int mask_index;
263 BOOL close_frame_received;
264 DWORD close_frame_receive_err;
265 USHORT status;
266 char reason[123];
267 DWORD reason_len;
268 char *send_frame_buffer;
269 unsigned int send_frame_buffer_size;
270 unsigned int send_remaining_size;
271 unsigned int bytes_in_send_frame_buffer;
272 unsigned int client_buffer_offset;
273 SRWLOCK send_lock;
274 volatile LONG pending_noncontrol_send;
275 enum fragment_type sending_fragment_type;
276 enum fragment_type receiving_fragment_type;
277 BOOL last_receive_final;
280 typedef void (*TASK_CALLBACK)( void *ctx, BOOL abort );
282 struct task_header
284 struct list entry;
285 TASK_CALLBACK callback;
286 struct object_header *obj;
287 volatile LONG refs;
288 volatile LONG completion_sent;
291 struct send_request
293 struct task_header task_hdr;
294 WCHAR *headers;
295 DWORD headers_len;
296 void *optional;
297 DWORD optional_len;
298 DWORD total_len;
299 DWORD_PTR context;
302 struct receive_response
304 struct task_header task_hdr;
307 struct query_data
309 struct task_header task_hdr;
310 DWORD *available;
313 struct read_data
315 struct task_header task_hdr;
316 void *buffer;
317 DWORD to_read;
318 DWORD *read;
321 struct write_data
323 struct task_header task_hdr;
324 const void *buffer;
325 DWORD to_write;
326 DWORD *written;
329 struct socket_send
331 struct task_header task_hdr;
332 WINHTTP_WEB_SOCKET_BUFFER_TYPE type;
333 const void *buf;
334 DWORD len;
335 WSAOVERLAPPED ovr;
336 BOOL complete_async;
339 struct socket_receive
341 struct task_header task_hdr;
342 void *buf;
343 DWORD len;
346 struct socket_shutdown
348 struct task_header task_hdr;
349 USHORT status;
350 char reason[123];
351 DWORD len;
352 BOOL send_callback;
353 WSAOVERLAPPED ovr;
354 BOOL complete_async;
357 struct object_header *addref_object( struct object_header * ) DECLSPEC_HIDDEN;
358 struct object_header *grab_object( HINTERNET ) DECLSPEC_HIDDEN;
359 void release_object( struct object_header * ) DECLSPEC_HIDDEN;
360 HINTERNET alloc_handle( struct object_header * ) DECLSPEC_HIDDEN;
361 BOOL free_handle( HINTERNET ) DECLSPEC_HIDDEN;
363 void send_callback( struct object_header *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN;
364 void close_connection( struct request * ) DECLSPEC_HIDDEN;
365 void init_queue( struct queue *queue ) DECLSPEC_HIDDEN;
366 void stop_queue( struct queue * ) DECLSPEC_HIDDEN;
368 void netconn_close( struct netconn * ) DECLSPEC_HIDDEN;
369 DWORD netconn_create( struct hostdata *, const struct sockaddr_storage *, int, struct netconn ** ) DECLSPEC_HIDDEN;
370 void netconn_unload( void ) DECLSPEC_HIDDEN;
371 ULONG netconn_query_data_available( struct netconn * ) DECLSPEC_HIDDEN;
372 DWORD netconn_recv( struct netconn *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
373 DWORD netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
374 DWORD netconn_secure_connect( struct netconn *, WCHAR *, DWORD, CredHandle *, BOOL ) DECLSPEC_HIDDEN;
375 DWORD netconn_send( struct netconn *, const void *, size_t, int *, WSAOVERLAPPED * ) DECLSPEC_HIDDEN;
376 BOOL netconn_wait_overlapped_result( struct netconn *conn, WSAOVERLAPPED *ovr, DWORD *len ) DECLSPEC_HIDDEN;
377 void netconn_cancel_io( struct netconn *conn ) DECLSPEC_HIDDEN;
378 DWORD netconn_set_timeout( struct netconn *, BOOL, int ) DECLSPEC_HIDDEN;
379 BOOL netconn_is_alive( struct netconn * ) DECLSPEC_HIDDEN;
380 const void *netconn_get_certificate( struct netconn * ) DECLSPEC_HIDDEN;
381 int netconn_get_cipher_strength( struct netconn * ) DECLSPEC_HIDDEN;
383 BOOL set_cookies( struct request *, const WCHAR * ) DECLSPEC_HIDDEN;
384 DWORD add_cookie_headers( struct request * ) DECLSPEC_HIDDEN;
385 DWORD add_request_headers( struct request *, const WCHAR *, DWORD, DWORD ) DECLSPEC_HIDDEN;
386 void destroy_cookies( struct session * ) DECLSPEC_HIDDEN;
387 BOOL set_server_for_hostname( struct connect *, const WCHAR *, INTERNET_PORT ) DECLSPEC_HIDDEN;
388 void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
390 void release_host( struct hostdata * ) DECLSPEC_HIDDEN;
391 DWORD process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOOL ) DECLSPEC_HIDDEN;
393 extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
394 void release_typelib( void ) DECLSPEC_HIDDEN;
396 static inline WCHAR *strdupW( const WCHAR *src )
398 WCHAR *dst;
400 if (!src) return NULL;
401 dst = malloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
402 if (dst) lstrcpyW( dst, src );
403 return dst;
406 static inline WCHAR *strdupAW( const char *src )
408 WCHAR *dst = NULL;
409 if (src)
411 int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
412 if ((dst = malloc( len * sizeof(WCHAR) )))
413 MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
415 return dst;
418 static inline char *strdupWA( const WCHAR *src )
420 char *dst = NULL;
421 if (src)
423 int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
424 if ((dst = malloc( len )))
425 WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
427 return dst;
430 static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
432 char *dst = NULL;
433 if (src)
435 int len = WideCharToMultiByte( CP_ACP, 0, src, size, NULL, 0, NULL, NULL ) + 1;
436 if ((dst = malloc( len )))
438 WideCharToMultiByte( CP_ACP, 0, src, size, dst, len, NULL, NULL );
439 dst[len - 1] = 0;
442 return dst;
445 extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
447 #define MAX_FRAME_BUFFER_SIZE 65536
449 #endif /* _WINE_WINHTTP_PRIVATE_H_ */