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_
26 #include "wine/list.h"
28 #define WINHTTP_HANDLE_TYPE_SOCKET 4
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
);
43 const struct object_vtbl
*vtbl
;
47 DWORD redirect_policy
;
51 WINHTTP_STATUS_CALLBACK callback
;
55 volatile LONG pending_sends
;
56 volatile LONG pending_receives
;
66 struct list connections
;
71 struct object_header hdr
;
79 int receive_response_timeout
;
82 WCHAR
*proxy_username
;
83 WCHAR
*proxy_password
;
84 struct list cookie_cache
;
86 DWORD secure_protocols
;
88 unsigned int websocket_receive_buffer_size
;
89 unsigned int websocket_send_buffer_size
;
94 struct object_header hdr
;
95 struct session
*session
;
96 WCHAR
*hostname
; /* final destination of the request */
97 WCHAR
*servername
; /* name of the server we directly connect to */
100 INTERNET_PORT hostport
;
101 INTERNET_PORT serverport
;
102 struct sockaddr_storage sockaddr
;
111 struct sockaddr_storage sockaddr
;
112 BOOL secure
; /* SSL active on connection? */
113 struct hostdata
*host
;
114 ULONGLONG keep_until
;
116 SecPkgContext_StreamSizes ssl_sizes
;
117 char *ssl_read_buf
, *ssl_write_buf
;
130 BOOL is_request
; /* part of request headers? */
154 enum auth_scheme scheme
;
161 unsigned int data_len
;
162 BOOL finished
; /* finished authenticating */
168 struct list queued_tasks
;
169 BOOL callback_running
;
174 REQUEST_FLAG_WEBSOCKET_UPGRADE
= 0x01,
177 enum request_response_state
179 REQUEST_RESPONSE_STATE_NONE
,
180 REQUEST_RESPONSE_STATE_SENDING_REQUEST
,
181 REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED
,
182 REQUEST_RESPONSE_STATE_REQUEST_SENT
,
183 REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REQUEST_SENT
,
184 REQUEST_RESPONSE_STATE_REPLY_RECEIVED
,
185 REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REPLY_RECEIVED
,
186 REQUEST_RESPONSE_RECURSIVE_REQUEST
,
187 REQUEST_RESPONSE_STATE_RESPONSE_RECEIVED
,
192 struct object_header hdr
;
193 struct connect
*connect
;
194 enum request_flags flags
;
201 struct netconn
*netconn
;
202 DWORD security_flags
;
203 BOOL check_revocation
;
204 const CERT_CONTEXT
*server_cert
;
205 const CERT_CONTEXT
*client_cert
;
206 CredHandle cred_handle
;
207 BOOL cred_handle_initialized
;
212 int receive_response_timeout
;
214 DWORD redirect_count
; /* total number of redirects during this request */
216 DWORD content_length
; /* total number of bytes to be read */
217 DWORD content_read
; /* bytes read so far */
218 BOOL read_chunked
; /* are we reading in chunked mode? */
219 BOOL read_chunked_eof
; /* end of stream in chunked mode */
220 BOOL read_chunked_size
; /* chunk size remaining */
221 DWORD read_pos
; /* current read position in read_buf */
222 DWORD read_size
; /* valid data size in read_buf */
223 char read_buf
[8192]; /* buffer for already read but not returned data */
224 struct header
*headers
;
226 struct authinfo
*authinfo
;
227 struct authinfo
*proxy_authinfo
;
233 } creds
[TARGET_MAX
][SCHEME_MAX
];
234 unsigned int websocket_receive_buffer_size
;
235 unsigned int websocket_send_buffer_size
, websocket_set_send_buffer_size
;
237 DWORD read_reply_status
;
238 enum request_response_state state
;
243 SOCKET_STATE_OPEN
= 0,
244 SOCKET_STATE_SHUTDOWN
= 1,
245 SOCKET_STATE_CLOSED
= 2,
251 SOCKET_OPCODE_CONTINUE
= 0x00,
252 SOCKET_OPCODE_TEXT
= 0x01,
253 SOCKET_OPCODE_BINARY
= 0x02,
254 SOCKET_OPCODE_RESERVED3
= 0x03,
255 SOCKET_OPCODE_RESERVED4
= 0x04,
256 SOCKET_OPCODE_RESERVED5
= 0x05,
257 SOCKET_OPCODE_RESERVED6
= 0x06,
258 SOCKET_OPCODE_RESERVED7
= 0x07,
259 SOCKET_OPCODE_CLOSE
= 0x08,
260 SOCKET_OPCODE_PING
= 0x09,
261 SOCKET_OPCODE_PONG
= 0x0a,
262 SOCKET_OPCODE_INVALID
= 0xff,
267 SOCKET_FRAGMENT_NONE
,
268 SOCKET_FRAGMENT_BINARY
,
269 SOCKET_FRAGMENT_UTF8
,
274 struct object_header hdr
;
275 struct netconn
*netconn
;
276 int keepalive_interval
;
277 unsigned int send_buffer_size
;
278 enum socket_state state
;
281 enum socket_opcode opcode
;
284 unsigned int mask_index
;
285 BOOL close_frame_received
;
286 DWORD close_frame_receive_err
;
290 char *send_frame_buffer
;
291 unsigned int send_frame_buffer_size
;
292 unsigned int send_remaining_size
;
293 unsigned int bytes_in_send_frame_buffer
;
294 unsigned int client_buffer_offset
;
296 unsigned int bytes_in_read_buffer
;
298 volatile LONG pending_noncontrol_send
;
299 enum fragment_type sending_fragment_type
;
300 enum fragment_type receiving_fragment_type
;
301 BOOL last_receive_final
;
304 typedef void (*TASK_CALLBACK
)( void *ctx
, BOOL abort
);
309 TASK_CALLBACK callback
;
310 struct object_header
*obj
;
312 volatile LONG completion_sent
;
317 struct task_header task_hdr
;
326 struct receive_response
328 struct task_header task_hdr
;
333 struct task_header task_hdr
;
339 struct task_header task_hdr
;
347 struct task_header task_hdr
;
355 struct task_header task_hdr
;
356 WINHTTP_WEB_SOCKET_BUFFER_TYPE type
;
363 struct socket_receive
365 struct task_header task_hdr
;
370 struct socket_shutdown
372 struct task_header task_hdr
;
381 struct object_header
*addref_object( struct object_header
* ) DECLSPEC_HIDDEN
;
382 struct object_header
*grab_object( HINTERNET
) DECLSPEC_HIDDEN
;
383 void release_object( struct object_header
* ) DECLSPEC_HIDDEN
;
384 HINTERNET
alloc_handle( struct object_header
* ) DECLSPEC_HIDDEN
;
385 BOOL
free_handle( HINTERNET
) DECLSPEC_HIDDEN
;
387 void send_callback( struct object_header
*, DWORD
, LPVOID
, DWORD
) DECLSPEC_HIDDEN
;
388 void close_connection( struct request
* ) DECLSPEC_HIDDEN
;
389 void init_queue( struct queue
*queue
) DECLSPEC_HIDDEN
;
390 void stop_queue( struct queue
* ) DECLSPEC_HIDDEN
;
392 void netconn_addref( struct netconn
* ) DECLSPEC_HIDDEN
;
393 void netconn_release( struct netconn
* ) DECLSPEC_HIDDEN
;
394 DWORD
netconn_create( struct hostdata
*, const struct sockaddr_storage
*, int, struct netconn
** ) DECLSPEC_HIDDEN
;
395 void netconn_unload( void ) DECLSPEC_HIDDEN
;
396 ULONG
netconn_query_data_available( struct netconn
* ) DECLSPEC_HIDDEN
;
397 DWORD
netconn_recv( struct netconn
*, void *, size_t, int, int * ) DECLSPEC_HIDDEN
;
398 DWORD
netconn_resolve( WCHAR
*, INTERNET_PORT
, struct sockaddr_storage
*, int ) DECLSPEC_HIDDEN
;
399 DWORD
netconn_secure_connect( struct netconn
*, WCHAR
*, DWORD
, CredHandle
*, BOOL
) DECLSPEC_HIDDEN
;
400 DWORD
netconn_send( struct netconn
*, const void *, size_t, int *, WSAOVERLAPPED
* ) DECLSPEC_HIDDEN
;
401 BOOL
netconn_wait_overlapped_result( struct netconn
*conn
, WSAOVERLAPPED
*ovr
, DWORD
*len
) DECLSPEC_HIDDEN
;
402 void netconn_cancel_io( struct netconn
*conn
) DECLSPEC_HIDDEN
;
403 DWORD
netconn_set_timeout( struct netconn
*, BOOL
, int ) DECLSPEC_HIDDEN
;
404 BOOL
netconn_is_alive( struct netconn
* ) DECLSPEC_HIDDEN
;
405 const void *netconn_get_certificate( struct netconn
* ) DECLSPEC_HIDDEN
;
406 int netconn_get_cipher_strength( struct netconn
* ) DECLSPEC_HIDDEN
;
408 BOOL
set_cookies( struct request
*, const WCHAR
* ) DECLSPEC_HIDDEN
;
409 DWORD
add_cookie_headers( struct request
* ) DECLSPEC_HIDDEN
;
410 DWORD
add_request_headers( struct request
*, const WCHAR
*, DWORD
, DWORD
) DECLSPEC_HIDDEN
;
411 void destroy_cookies( struct session
* ) DECLSPEC_HIDDEN
;
412 BOOL
set_server_for_hostname( struct connect
*, const WCHAR
*, INTERNET_PORT
) DECLSPEC_HIDDEN
;
413 void destroy_authinfo( struct authinfo
* ) DECLSPEC_HIDDEN
;
415 void release_host( struct hostdata
* ) DECLSPEC_HIDDEN
;
416 DWORD
process_header( struct request
*, const WCHAR
*, const WCHAR
*, DWORD
, BOOL
) DECLSPEC_HIDDEN
;
418 extern HRESULT
WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN
;
419 void release_typelib( void ) DECLSPEC_HIDDEN
;
421 static inline WCHAR
*strdupAW( const char *src
)
426 int len
= MultiByteToWideChar( CP_ACP
, 0, src
, -1, NULL
, 0 );
427 if ((dst
= malloc( len
* sizeof(WCHAR
) )))
428 MultiByteToWideChar( CP_ACP
, 0, src
, -1, dst
, len
);
433 static inline char *strdupWA( const WCHAR
*src
)
438 int len
= WideCharToMultiByte( CP_ACP
, 0, src
, -1, NULL
, 0, NULL
, NULL
);
439 if ((dst
= malloc( len
)))
440 WideCharToMultiByte( CP_ACP
, 0, src
, -1, dst
, len
, NULL
, NULL
);
445 static inline char *strdupWA_sized( const WCHAR
*src
, DWORD size
)
450 int len
= WideCharToMultiByte( CP_ACP
, 0, src
, size
, NULL
, 0, NULL
, NULL
) + 1;
451 if ((dst
= malloc( len
)))
453 WideCharToMultiByte( CP_ACP
, 0, src
, size
, dst
, len
, NULL
, NULL
);
460 extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN
;
462 #define MIN_WEBSOCKET_SEND_BUFFER_SIZE 16
464 #endif /* _WINE_WINHTTP_PRIVATE_H_ */