winhttp: Only read server reply in send_request() if the whole request is sent.
[wine.git] / dlls / winhttp / winhttp_private.h
blobbf1e60e2ceec77cf339a4cbae5cb74a088dccfcb
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;
88 unsigned int websocket_receive_buffer_size;
89 unsigned int websocket_send_buffer_size;
92 struct connect
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 */
98 WCHAR *username;
99 WCHAR *password;
100 INTERNET_PORT hostport;
101 INTERNET_PORT serverport;
102 struct sockaddr_storage sockaddr;
103 BOOL resolved;
106 struct netconn
108 struct list entry;
109 LONG refs;
110 int socket;
111 struct sockaddr_storage sockaddr;
112 BOOL secure; /* SSL active on connection? */
113 struct hostdata *host;
114 ULONGLONG keep_until;
115 CtxtHandle ssl_ctx;
116 SecPkgContext_StreamSizes ssl_sizes;
117 char *ssl_read_buf, *ssl_write_buf;
118 char *extra_buf;
119 size_t extra_len;
120 char *peek_msg;
121 char *peek_msg_mem;
122 size_t peek_len;
123 HANDLE port;
126 struct header
128 WCHAR *field;
129 WCHAR *value;
130 BOOL is_request; /* part of request headers? */
133 enum auth_target
135 TARGET_INVALID = -1,
136 TARGET_SERVER,
137 TARGET_PROXY,
138 TARGET_MAX
141 enum auth_scheme
143 SCHEME_INVALID = -1,
144 SCHEME_BASIC,
145 SCHEME_NTLM,
146 SCHEME_PASSPORT,
147 SCHEME_DIGEST,
148 SCHEME_NEGOTIATE,
149 SCHEME_MAX
152 struct authinfo
154 enum auth_scheme scheme;
155 CredHandle cred;
156 CtxtHandle ctx;
157 TimeStamp exp;
158 ULONG attr;
159 ULONG max_token;
160 char *data;
161 unsigned int data_len;
162 BOOL finished; /* finished authenticating */
165 struct queue
167 SRWLOCK lock;
168 struct list queued_tasks;
169 BOOL callback_running;
172 enum request_flags
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,
190 struct request
192 struct object_header hdr;
193 struct connect *connect;
194 enum request_flags flags;
195 WCHAR *verb;
196 WCHAR *path;
197 WCHAR *version;
198 WCHAR *raw_headers;
199 void *optional;
200 DWORD optional_len;
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;
208 int resolve_timeout;
209 int connect_timeout;
210 int send_timeout;
211 int receive_timeout;
212 int receive_response_timeout;
213 DWORD max_redirects;
214 DWORD redirect_count; /* total number of redirects during this request */
215 WCHAR *status_text;
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;
225 DWORD num_headers;
226 struct authinfo *authinfo;
227 struct authinfo *proxy_authinfo;
228 struct queue queue;
229 struct
231 WCHAR *username;
232 WCHAR *password;
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;
236 int read_reply_len;
237 DWORD read_reply_status;
238 enum request_response_state state;
241 enum socket_state
243 SOCKET_STATE_OPEN = 0,
244 SOCKET_STATE_SHUTDOWN = 1,
245 SOCKET_STATE_CLOSED = 2,
248 /* rfc6455 */
249 enum socket_opcode
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,
265 enum fragment_type
267 SOCKET_FRAGMENT_NONE,
268 SOCKET_FRAGMENT_BINARY,
269 SOCKET_FRAGMENT_UTF8,
272 struct socket
274 struct object_header hdr;
275 struct netconn *netconn;
276 int keepalive_interval;
277 unsigned int send_buffer_size;
278 enum socket_state state;
279 struct queue send_q;
280 struct queue recv_q;
281 enum socket_opcode opcode;
282 DWORD read_size;
283 char mask[4];
284 unsigned int mask_index;
285 BOOL close_frame_received;
286 DWORD close_frame_receive_err;
287 USHORT status;
288 char reason[123];
289 DWORD reason_len;
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;
295 char *read_buffer;
296 unsigned int bytes_in_read_buffer;
297 SRWLOCK send_lock;
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 );
306 struct task_header
308 struct list entry;
309 TASK_CALLBACK callback;
310 struct object_header *obj;
311 volatile LONG refs;
312 volatile LONG completion_sent;
315 struct send_request
317 struct task_header task_hdr;
318 WCHAR *headers;
319 DWORD headers_len;
320 void *optional;
321 DWORD optional_len;
322 DWORD total_len;
323 DWORD_PTR context;
326 struct receive_response
328 struct task_header task_hdr;
331 struct query_data
333 struct task_header task_hdr;
334 DWORD *available;
337 struct read_data
339 struct task_header task_hdr;
340 void *buffer;
341 DWORD to_read;
342 DWORD *read;
345 struct write_data
347 struct task_header task_hdr;
348 const void *buffer;
349 DWORD to_write;
350 DWORD *written;
353 struct socket_send
355 struct task_header task_hdr;
356 WINHTTP_WEB_SOCKET_BUFFER_TYPE type;
357 const void *buf;
358 DWORD len;
359 WSAOVERLAPPED ovr;
360 BOOL complete_async;
363 struct socket_receive
365 struct task_header task_hdr;
366 void *buf;
367 DWORD len;
370 struct socket_shutdown
372 struct task_header task_hdr;
373 USHORT status;
374 char reason[123];
375 DWORD len;
376 BOOL send_callback;
377 WSAOVERLAPPED ovr;
378 BOOL complete_async;
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 )
423 WCHAR *dst = NULL;
424 if (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 );
430 return dst;
433 static inline char *strdupWA( const WCHAR *src )
435 char *dst = NULL;
436 if (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 );
442 return dst;
445 static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
447 char *dst = NULL;
448 if (src)
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 );
454 dst[len - 1] = 0;
457 return dst;
460 extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
462 #define MIN_WEBSOCKET_SEND_BUFFER_SIZE 16
464 #endif /* _WINE_WINHTTP_PRIVATE_H_ */