mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / winhttp / winhttp_private.h
blobe279e58a5fe849de7bfdda20fdd4549f1badeb3a
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 "wine/heap.h"
23 #include "wine/list.h"
25 #include "ole2.h"
26 #include "sspi.h"
27 #include "wincrypt.h"
29 #define WINHTTP_HANDLE_TYPE_SOCKET 4
31 struct object_header;
32 struct object_vtbl
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 struct list entry;
56 struct hostdata
58 struct list entry;
59 LONG ref;
60 WCHAR *hostname;
61 INTERNET_PORT port;
62 BOOL secure;
63 struct list connections;
66 struct session
68 struct object_header hdr;
69 CRITICAL_SECTION cs;
70 WCHAR *agent;
71 DWORD access;
72 int resolve_timeout;
73 int connect_timeout;
74 int send_timeout;
75 int receive_timeout;
76 int receive_response_timeout;
77 WCHAR *proxy_server;
78 WCHAR *proxy_bypass;
79 WCHAR *proxy_username;
80 WCHAR *proxy_password;
81 struct list cookie_cache;
82 HANDLE unload_event;
83 DWORD secure_protocols;
84 DWORD passport_flags;
87 struct connect
89 struct object_header hdr;
90 struct session *session;
91 WCHAR *hostname; /* final destination of the request */
92 WCHAR *servername; /* name of the server we directly connect to */
93 WCHAR *username;
94 WCHAR *password;
95 INTERNET_PORT hostport;
96 INTERNET_PORT serverport;
97 struct sockaddr_storage sockaddr;
98 BOOL resolved;
101 struct netconn
103 struct list entry;
104 int socket;
105 struct sockaddr_storage sockaddr;
106 BOOL secure; /* SSL active on connection? */
107 struct hostdata *host;
108 ULONGLONG keep_until;
109 CtxtHandle ssl_ctx;
110 SecPkgContext_StreamSizes ssl_sizes;
111 char *ssl_buf;
112 char *extra_buf;
113 size_t extra_len;
114 char *peek_msg;
115 char *peek_msg_mem;
116 size_t peek_len;
119 struct header
121 WCHAR *field;
122 WCHAR *value;
123 BOOL is_request; /* part of request headers? */
126 enum auth_target
128 TARGET_INVALID = -1,
129 TARGET_SERVER,
130 TARGET_PROXY,
131 TARGET_MAX
134 enum auth_scheme
136 SCHEME_INVALID = -1,
137 SCHEME_BASIC,
138 SCHEME_NTLM,
139 SCHEME_PASSPORT,
140 SCHEME_DIGEST,
141 SCHEME_NEGOTIATE,
142 SCHEME_MAX
145 struct authinfo
147 enum auth_scheme scheme;
148 CredHandle cred;
149 CtxtHandle ctx;
150 TimeStamp exp;
151 ULONG attr;
152 ULONG max_token;
153 char *data;
154 unsigned int data_len;
155 BOOL finished; /* finished authenticating */
158 struct queue
160 TP_POOL *pool;
161 TP_CALLBACK_ENVIRON env;
164 enum request_flags
166 REQUEST_FLAG_WEBSOCKET_UPGRADE = 0x01,
169 struct request
171 struct object_header hdr;
172 struct connect *connect;
173 enum request_flags flags;
174 WCHAR *verb;
175 WCHAR *path;
176 WCHAR *version;
177 WCHAR *raw_headers;
178 void *optional;
179 DWORD optional_len;
180 struct netconn *netconn;
181 DWORD security_flags;
182 BOOL check_revocation;
183 const CERT_CONTEXT *server_cert;
184 const CERT_CONTEXT *client_cert;
185 CredHandle cred_handle;
186 BOOL cred_handle_initialized;
187 int resolve_timeout;
188 int connect_timeout;
189 int send_timeout;
190 int receive_timeout;
191 int receive_response_timeout;
192 DWORD max_redirects;
193 DWORD redirect_count; /* total number of redirects during this request */
194 WCHAR *status_text;
195 DWORD content_length; /* total number of bytes to be read */
196 DWORD content_read; /* bytes read so far */
197 BOOL read_chunked; /* are we reading in chunked mode? */
198 BOOL read_chunked_eof; /* end of stream in chunked mode */
199 BOOL read_chunked_size; /* chunk size remaining */
200 DWORD read_pos; /* current read position in read_buf */
201 DWORD read_size; /* valid data size in read_buf */
202 char read_buf[8192]; /* buffer for already read but not returned data */
203 struct header *headers;
204 DWORD num_headers;
205 struct authinfo *authinfo;
206 struct authinfo *proxy_authinfo;
207 struct queue queue;
208 struct
210 WCHAR *username;
211 WCHAR *password;
212 } creds[TARGET_MAX][SCHEME_MAX];
215 enum socket_state
217 SOCKET_STATE_OPEN = 0,
218 SOCKET_STATE_SHUTDOWN = 1,
219 SOCKET_STATE_CLOSED = 2,
222 /* rfc6455 */
223 enum socket_opcode
225 SOCKET_OPCODE_CONTINUE = 0x00,
226 SOCKET_OPCODE_TEXT = 0x01,
227 SOCKET_OPCODE_BINARY = 0x02,
228 SOCKET_OPCODE_RESERVED3 = 0x03,
229 SOCKET_OPCODE_RESERVED4 = 0x04,
230 SOCKET_OPCODE_RESERVED5 = 0x05,
231 SOCKET_OPCODE_RESERVED6 = 0x06,
232 SOCKET_OPCODE_RESERVED7 = 0x07,
233 SOCKET_OPCODE_CLOSE = 0x08,
234 SOCKET_OPCODE_PING = 0x09,
235 SOCKET_OPCODE_PONG = 0x0a,
236 SOCKET_OPCODE_INVALID = 0xff,
239 struct socket
241 struct object_header hdr;
242 struct request *request;
243 enum socket_state state;
244 struct queue send_q;
245 struct queue recv_q;
246 enum socket_opcode opcode;
247 DWORD read_size;
248 USHORT status;
249 char reason[123];
250 DWORD reason_len;
253 struct send_request
255 struct request *request;
256 WCHAR *headers;
257 DWORD headers_len;
258 void *optional;
259 DWORD optional_len;
260 DWORD total_len;
261 DWORD_PTR context;
264 struct receive_response
266 struct request *request;
269 struct query_data
271 struct request *request;
272 DWORD *available;
275 struct read_data
277 struct request *request;
278 void *buffer;
279 DWORD to_read;
280 DWORD *read;
283 struct write_data
285 struct request *request;
286 const void *buffer;
287 DWORD to_write;
288 DWORD *written;
291 struct socket_send
293 struct socket *socket;
294 WINHTTP_WEB_SOCKET_BUFFER_TYPE type;
295 const void *buf;
296 DWORD len;
299 struct socket_receive
301 struct socket *socket;
302 void *buf;
303 DWORD len;
306 struct socket_shutdown
308 struct socket *socket;
309 USHORT status;
310 char reason[123];
311 DWORD len;
314 struct object_header *addref_object( struct object_header * ) DECLSPEC_HIDDEN;
315 struct object_header *grab_object( HINTERNET ) DECLSPEC_HIDDEN;
316 void release_object( struct object_header * ) DECLSPEC_HIDDEN;
317 HINTERNET alloc_handle( struct object_header * ) DECLSPEC_HIDDEN;
318 BOOL free_handle( HINTERNET ) DECLSPEC_HIDDEN;
320 void send_callback( struct object_header *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN;
321 void close_connection( struct request * ) DECLSPEC_HIDDEN;
322 void stop_queue( struct queue * ) DECLSPEC_HIDDEN;
324 void netconn_close( struct netconn * ) DECLSPEC_HIDDEN;
325 DWORD netconn_create( struct hostdata *, const struct sockaddr_storage *, int, struct netconn ** ) DECLSPEC_HIDDEN;
326 void netconn_unload( void ) DECLSPEC_HIDDEN;
327 ULONG netconn_query_data_available( struct netconn * ) DECLSPEC_HIDDEN;
328 DWORD netconn_recv( struct netconn *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
329 DWORD netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
330 DWORD netconn_secure_connect( struct netconn *, WCHAR *, DWORD, CredHandle *, BOOL ) DECLSPEC_HIDDEN;
331 DWORD netconn_send( struct netconn *, const void *, size_t, int * ) DECLSPEC_HIDDEN;
332 DWORD netconn_set_timeout( struct netconn *, BOOL, int ) DECLSPEC_HIDDEN;
333 BOOL netconn_is_alive( struct netconn * ) DECLSPEC_HIDDEN;
334 const void *netconn_get_certificate( struct netconn * ) DECLSPEC_HIDDEN;
335 int netconn_get_cipher_strength( struct netconn * ) DECLSPEC_HIDDEN;
337 BOOL set_cookies( struct request *, const WCHAR * ) DECLSPEC_HIDDEN;
338 DWORD add_cookie_headers( struct request * ) DECLSPEC_HIDDEN;
339 DWORD add_request_headers( struct request *, const WCHAR *, DWORD, DWORD ) DECLSPEC_HIDDEN;
340 void destroy_cookies( struct session * ) DECLSPEC_HIDDEN;
341 BOOL set_server_for_hostname( struct connect *, const WCHAR *, INTERNET_PORT ) DECLSPEC_HIDDEN;
342 void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
344 void release_host( struct hostdata * ) DECLSPEC_HIDDEN;
345 DWORD process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOOL ) DECLSPEC_HIDDEN;
347 extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
348 void release_typelib( void ) DECLSPEC_HIDDEN;
350 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
352 return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
355 static inline WCHAR *strdupW( const WCHAR *src )
357 WCHAR *dst;
359 if (!src) return NULL;
360 dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
361 if (dst) lstrcpyW( dst, src );
362 return dst;
365 static inline WCHAR *strdupAW( const char *src )
367 WCHAR *dst = NULL;
368 if (src)
370 int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
371 if ((dst = heap_alloc( len * sizeof(WCHAR) )))
372 MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
374 return dst;
377 static inline char *strdupWA( const WCHAR *src )
379 char *dst = NULL;
380 if (src)
382 int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
383 if ((dst = heap_alloc( len )))
384 WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
386 return dst;
389 static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
391 char *dst = NULL;
392 if (src)
394 int len = WideCharToMultiByte( CP_ACP, 0, src, size, NULL, 0, NULL, NULL ) + 1;
395 if ((dst = heap_alloc( len )))
397 WideCharToMultiByte( CP_ACP, 0, src, size, dst, len, NULL, NULL );
398 dst[len - 1] = 0;
401 return dst;
404 extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
406 #endif /* _WINE_WINHTTP_PRIVATE_H_ */