ReactOS 0.4.16-dev-2491-g3dc6630
winhttp_private.h File Reference
#include <wine/heap.h>
#include "ole2.h"
#include "sspi.h"
#include "wincrypt.h"
#include "wine/list.h"
Include dependency graph for winhttp_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  object_vtbl
 
struct  object_header
 
struct  hostdata
 
struct  session
 
struct  connect
 
struct  netconn
 
struct  header
 
struct  authinfo
 
class  queue< _Tp, _Sequence >
 
struct  request
 
struct  socket
 
struct  task_header
 
struct  send_callback
 
struct  send_request
 
struct  receive_response
 
struct  query_data
 
struct  read_data
 
struct  write_data
 
struct  socket_send
 
struct  socket_receive
 
struct  socket_shutdown
 

Macros

#define WINHTTP_HANDLE_TYPE_SOCKET   4
 
#define MIN_WEBSOCKET_SEND_BUFFER_SIZE   16
 

Typedefs

typedef void(* TASK_CALLBACK) (void *ctx, BOOL abort)
 

Enumerations

enum  auth_target { TARGET_INVALID = -1 , TARGET_SERVER , TARGET_PROXY , TARGET_MAX }
 
enum  auth_scheme {
  SCHEME_INVALID = -1 , SCHEME_BASIC , SCHEME_NTLM , SCHEME_PASSPORT ,
  SCHEME_DIGEST , SCHEME_NEGOTIATE , SCHEME_MAX
}
 
enum  request_flags { REQUEST_FLAG_WEBSOCKET_UPGRADE = 0x01 }
 
enum  request_response_state {
  REQUEST_RESPONSE_STATE_NONE , REQUEST_RESPONSE_STATE_SENDING_REQUEST , REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED , REQUEST_RESPONSE_STATE_REQUEST_SENT ,
  REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REQUEST_SENT , REQUEST_RESPONSE_STATE_REPLY_RECEIVED , REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REPLY_RECEIVED , REQUEST_RESPONSE_RECURSIVE_REQUEST ,
  REQUEST_RESPONSE_STATE_RESPONSE_RECEIVED
}
 
enum  socket_state { SOCKET_STATE_OPEN = 0 , SOCKET_STATE_SHUTDOWN = 1 , SOCKET_STATE_CLOSED = 2 }
 
enum  socket_opcode {
  SOCKET_OPCODE_CONTINUE = 0x00 , SOCKET_OPCODE_TEXT = 0x01 , SOCKET_OPCODE_BINARY = 0x02 , SOCKET_OPCODE_RESERVED3 = 0x03 ,
  SOCKET_OPCODE_RESERVED4 = 0x04 , SOCKET_OPCODE_RESERVED5 = 0x05 , SOCKET_OPCODE_RESERVED6 = 0x06 , SOCKET_OPCODE_RESERVED7 = 0x07 ,
  SOCKET_OPCODE_CLOSE = 0x08 , SOCKET_OPCODE_PING = 0x09 , SOCKET_OPCODE_PONG = 0x0a , SOCKET_OPCODE_INVALID = 0xff
}
 
enum  fragment_type { SOCKET_FRAGMENT_NONE , SOCKET_FRAGMENT_BINARY , SOCKET_FRAGMENT_UTF8 }
 

Functions

struct object_headeraddref_object (struct object_header *)
 
struct object_headergrab_object (HINTERNET)
 
void release_object (struct object_header *)
 
HINTERNET alloc_handle (struct object_header *)
 
BOOL free_handle (HINTERNET)
 
void send_callback (struct object_header *, DWORD, LPVOID, DWORD)
 
void close_connection (struct request *)
 
void init_queue (struct queue *queue)
 
void stop_queue (struct queue *)
 
void netconn_addref (struct netconn *)
 
void netconn_release (struct netconn *)
 
DWORD netconn_create (struct hostdata *, const struct sockaddr_storage *, int, struct netconn **)
 
void netconn_unload (void)
 
ULONG netconn_query_data_available (struct netconn *)
 
DWORD netconn_recv (struct netconn *, void *, size_t, int, int *)
 
DWORD netconn_resolve (WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int)
 
DWORD netconn_secure_connect (struct netconn *, WCHAR *, DWORD, CredHandle *, BOOL)
 
DWORD netconn_send (struct netconn *, const void *, size_t, int *, WSAOVERLAPPED *)
 
BOOL netconn_wait_overlapped_result (struct netconn *conn, WSAOVERLAPPED *ovr, DWORD *len)
 
void netconn_cancel_io (struct netconn *conn)
 
DWORD netconn_set_timeout (struct netconn *, BOOL, int)
 
BOOL netconn_is_alive (struct netconn *)
 
const voidnetconn_get_certificate (struct netconn *)
 
int netconn_get_cipher_strength (struct netconn *)
 
BOOL set_cookies (struct request *, const WCHAR *)
 
DWORD add_cookie_headers (struct request *)
 
DWORD add_request_headers (struct request *, const WCHAR *, DWORD, DWORD)
 
void destroy_cookies (struct session *)
 
BOOL set_server_for_hostname (struct connect *, const WCHAR *, INTERNET_PORT)
 
void destroy_authinfo (struct authinfo *)
 
void release_host (struct hostdata *)
 
DWORD process_header (struct request *, const WCHAR *, const WCHAR *, DWORD, BOOL)
 
HRESULT WinHttpRequest_create (void **)
 
void release_typelib (void)
 
static WCHARstrdupAW (const char *src)
 
static charstrdupWA (const WCHAR *src)
 

Variables

HINSTANCE winhttp_instance
 

Macro Definition Documentation

◆ MIN_WEBSOCKET_SEND_BUFFER_SIZE

#define MIN_WEBSOCKET_SEND_BUFFER_SIZE   16

Definition at line 472 of file winhttp_private.h.

◆ WINHTTP_HANDLE_TYPE_SOCKET

#define WINHTTP_HANDLE_TYPE_SOCKET   4

Definition at line 35 of file winhttp_private.h.

Typedef Documentation

◆ TASK_CALLBACK

typedef void(* TASK_CALLBACK) (void *ctx, BOOL abort)

Definition at line 316 of file winhttp_private.h.

Enumeration Type Documentation

◆ auth_scheme

Enumerator
SCHEME_INVALID 
SCHEME_BASIC 
SCHEME_NTLM 
SCHEME_PASSPORT 
SCHEME_DIGEST 
SCHEME_NEGOTIATE 
SCHEME_MAX 

Definition at line 148 of file winhttp_private.h.

149{
150 SCHEME_INVALID = -1,
157};
@ SCHEME_BASIC
@ SCHEME_PASSPORT
@ SCHEME_DIGEST
@ SCHEME_INVALID
@ SCHEME_NTLM
@ SCHEME_NEGOTIATE
@ SCHEME_MAX

◆ auth_target

Enumerator
TARGET_INVALID 
TARGET_SERVER 
TARGET_PROXY 
TARGET_MAX 

Definition at line 140 of file winhttp_private.h.

141{
142 TARGET_INVALID = -1,
146};
@ TARGET_MAX
@ TARGET_INVALID
@ TARGET_SERVER
@ TARGET_PROXY

◆ fragment_type

Enumerator
SOCKET_FRAGMENT_NONE 
SOCKET_FRAGMENT_BINARY 
SOCKET_FRAGMENT_UTF8 

Definition at line 277 of file winhttp_private.h.

278{
282};
@ SOCKET_FRAGMENT_UTF8
@ SOCKET_FRAGMENT_NONE
@ SOCKET_FRAGMENT_BINARY

◆ request_flags

Enumerator
REQUEST_FLAG_WEBSOCKET_UPGRADE 

Definition at line 179 of file winhttp_private.h.

180{
182};
@ REQUEST_FLAG_WEBSOCKET_UPGRADE

◆ request_response_state

Enumerator
REQUEST_RESPONSE_STATE_NONE 
REQUEST_RESPONSE_STATE_SENDING_REQUEST 
REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED 
REQUEST_RESPONSE_STATE_REQUEST_SENT 
REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REQUEST_SENT 
REQUEST_RESPONSE_STATE_REPLY_RECEIVED 
REQUEST_RESPONSE_STATE_READ_RESPONSE_QUEUED_REPLY_RECEIVED 
REQUEST_RESPONSE_RECURSIVE_REQUEST 
REQUEST_RESPONSE_STATE_RESPONSE_RECEIVED 

Definition at line 184 of file winhttp_private.h.

◆ socket_opcode

Enumerator
SOCKET_OPCODE_CONTINUE 
SOCKET_OPCODE_TEXT 
SOCKET_OPCODE_BINARY 
SOCKET_OPCODE_RESERVED3 
SOCKET_OPCODE_RESERVED4 
SOCKET_OPCODE_RESERVED5 
SOCKET_OPCODE_RESERVED6 
SOCKET_OPCODE_RESERVED7 
SOCKET_OPCODE_CLOSE 
SOCKET_OPCODE_PING 
SOCKET_OPCODE_PONG 
SOCKET_OPCODE_INVALID 

Definition at line 261 of file winhttp_private.h.

262{
264 SOCKET_OPCODE_TEXT = 0x01,
271 SOCKET_OPCODE_CLOSE = 0x08,
272 SOCKET_OPCODE_PING = 0x09,
273 SOCKET_OPCODE_PONG = 0x0a,
275};
@ SOCKET_OPCODE_TEXT
@ SOCKET_OPCODE_PING
@ SOCKET_OPCODE_PONG
@ SOCKET_OPCODE_CONTINUE
@ SOCKET_OPCODE_BINARY
@ SOCKET_OPCODE_INVALID
@ SOCKET_OPCODE_RESERVED4
@ SOCKET_OPCODE_RESERVED3
@ SOCKET_OPCODE_CLOSE
@ SOCKET_OPCODE_RESERVED6
@ SOCKET_OPCODE_RESERVED7
@ SOCKET_OPCODE_RESERVED5

◆ socket_state

Enumerator
SOCKET_STATE_OPEN 
SOCKET_STATE_SHUTDOWN 
SOCKET_STATE_CLOSED 

Definition at line 253 of file winhttp_private.h.

254{
258};
@ SOCKET_STATE_SHUTDOWN
@ SOCKET_STATE_CLOSED
@ SOCKET_STATE_OPEN

Function Documentation

◆ add_cookie_headers()

DWORD add_cookie_headers ( struct request request)

Definition at line 322 of file cookie.c.

323{
324 struct list *domain_cursor;
325 struct session *session = request->connect->session;
327
329
330 LIST_FOR_EACH( domain_cursor, &session->cookie_cache )
331 {
332 struct domain *domain = LIST_ENTRY( domain_cursor, struct domain, entry );
333 if (domain_match( request->connect->servername, domain, TRUE ))
334 {
335 struct list *cookie_cursor;
336 TRACE("found domain %s\n", debugstr_w(domain->name));
337
338 LIST_FOR_EACH( cookie_cursor, &domain->cookies )
339 {
340 struct cookie *cookie = LIST_ENTRY( cookie_cursor, struct cookie, entry );
341
342 TRACE("comparing path %s with %s\n", debugstr_w(request->path), debugstr_w(cookie->path));
343
344 if (wcsstr( request->path, cookie->path ) == request->path)
345 {
346 static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '};
347 int len, len_cookie = ARRAY_SIZE( cookieW ), len_name = lstrlenW( cookie->name );
348 WCHAR *header;
349
350 len = len_cookie + len_name;
351 if (cookie->value) len += lstrlenW( cookie->value ) + 1;
352 if (!(header = malloc( (len + 1) * sizeof(WCHAR) )))
353 {
355 return ERROR_OUTOFMEMORY;
356 }
357
358 memcpy( header, cookieW, len_cookie * sizeof(WCHAR) );
359 lstrcpyW( header + len_cookie, cookie->name );
360 if (cookie->value)
361 {
362 header[len_cookie + len_name] = '=';
363 lstrcpyW( header + len_cookie + len_name + 1, cookie->value );
364 }
365
366 TRACE("%s\n", debugstr_w(header));
369 free( header );
370 }
371 }
372 }
373 }
374
376 return ret;
377}
#define ARRAY_SIZE(A)
Definition: main.h:20
Definition: list.h:37
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
Definition: wcs.c:2993
return ret
Definition: mutex.c:146
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DWORD add_request_headers(struct request *request, const WCHAR *headers, DWORD len, DWORD flags)
Definition: request.c:485
#define LIST_FOR_EACH(cursor, list)
Definition: list.h:188
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cookie.c:34
WCHAR * name
Definition: cookie.c:36
WCHAR * value
Definition: cookie.c:37
WCHAR * path
Definition: cookie.c:38
Definition: cookie.c:42
WCHAR * name
Definition: cookie.c:44
struct list cookies
Definition: cookie.c:45
Definition: tftpd.h:86
char path[256]
Definition: tftpd.h:94
struct connect * connect
CRITICAL_SECTION cs
struct list cookie_cache
#define LIST_ENTRY(type)
Definition: queue.h:175
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static BOOL domain_match(const WCHAR *name, struct domain *domain, BOOL partial)
Definition: cookie.c:81
#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
Definition: winhttp.h:94
#define WINHTTP_ADDREQ_FLAG_ADD
Definition: winhttp.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by send_request().

◆ add_request_headers()

DWORD add_request_headers ( struct request request,
const WCHAR headers,
DWORD  len,
DWORD  flags 
)

Definition at line 485 of file request.c.

486{
488 struct header *header;
489 const WCHAR *p, *q;
490
491 if (len == ~0u) len = lstrlenW( headers );
492 if (!len) return ERROR_SUCCESS;
493
494 p = headers;
495 do
496 {
497 const WCHAR *end;
498
499 if (p >= headers + len) break;
500
501 for (q = p; q < headers + len && *q != '\r' && *q != '\n'; ++q)
502 ;
503 end = q;
504 while (*q == '\r' || *q == '\n')
505 ++q;
506
507 if ((header = parse_header( p, end - p, FALSE )))
508 {
511 }
512 p = q;
513 } while (!ret);
514
515 return ret;
516}
#define FALSE
Definition: types.h:117
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLbitfield flags
Definition: glext.h:7161
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
static struct header * parse_header(const WCHAR *string, size_t string_len, BOOL reply)
Definition: request.c:310
static void free_header(struct header *header)
Definition: request.c:282
DWORD process_header(struct request *request, const WCHAR *field, const WCHAR *value, DWORD flags, BOOL request_only)
Definition: request.c:424
vector< Header * > headers
Definition: sdkparse.cpp:39
WCHAR * field
WCHAR * value
#define ERROR_WINHTTP_INVALID_HEADER
Definition: winhttp.h:261

Referenced by add_cookie_headers(), send_request(), and WinHttpAddRequestHeaders().

◆ addref_object()

struct object_header * addref_object ( struct object_header hdr)

Definition at line 48 of file handle.c.

49{
50 ULONG refs = InterlockedIncrement( &hdr->refs );
51 TRACE( "%p -> refcount = %lu\n", hdr, refs );
52 return hdr;
53}
#define InterlockedIncrement
Definition: armddk.h:53
char hdr[14]
Definition: iptest.cpp:33
uint32_t ULONG
Definition: typedefs.h:59

Referenced by alloc_handle(), grab_object(), queue_task(), WinHttpConnect(), and WinHttpOpenRequest().

◆ alloc_handle()

HINTERNET alloc_handle ( struct object_header hdr)

Definition at line 86 of file handle.c.

87{
88 struct object_header **p;
90
91 hdr->handle = NULL;
92
94 if (!max_handles)
95 {
97 if (!(p = calloc( 1, sizeof(*p) * num ))) goto end;
98 handles = p;
100 }
102 {
103 size_t new_size, old_size = max_handles * sizeof(*handles);
104 num = max_handles * 2;
105 new_size = num * sizeof(*handles);
106 if (!(p = realloc( handles, new_size ))) goto end;
107 memset( (char *)p + old_size, 0, new_size - old_size );
108 handles = p;
110 }
112 if (handles[handle]) ERR("handle isn't free but should be\n");
113
115 hdr->handle = (HINTERNET)(handle + 1);
117
118end:
120 return hdr->handle;
121}
#define ERR(fmt,...)
Definition: precomp.h:57
#define realloc
Definition: debug_ros.c:6
#define NULL
Definition: types.h:112
static CRITICAL_SECTION handle_cs
Definition: handle.c:35
#define HANDLE_CHUNK_SIZE
Definition: handle.c:33
static struct object_header ** handles
Definition: handle.c:44
static ULONG_PTR max_handles
Definition: handle.c:46
struct object_header * addref_object(struct object_header *hdr)
Definition: handle.c:48
static ULONG_PTR next_handle
Definition: handle.c:45
size_t const old_size
Definition: expand.cpp:65
size_t const new_size
Definition: expand.cpp:66
GLuint GLuint num
Definition: glext.h:9618
#define calloc
Definition: rosglue.h:14
#define memset(x, y, z)
Definition: compat.h:39
HINTERNET handle
uint32_t ULONG_PTR
Definition: typedefs.h:65
LPVOID HINTERNET
Definition: winhttp.h:37

◆ close_connection()

void close_connection ( struct request request)

Definition at line 1740 of file request.c.

1741{
1742 if (!request->netconn) return;
1743
1745 request->netconn = NULL;
1746}
void netconn_release(struct netconn *conn)
Definition: net.c:295
struct netconn * netconn

◆ destroy_authinfo()

void destroy_authinfo ( struct authinfo authinfo)

Definition at line 1097 of file request.c.

1098{
1099 if (!authinfo) return;
1100
1101 if (SecIsValidHandle( &authinfo->ctx ))
1105
1106 free( authinfo->data );
1107 free( authinfo );
1108}
#define SecIsValidHandle(x)
Definition: sspi.h:63
char * data
CredHandle cred
CtxtHandle ctx
SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
Definition: wrapper.c:450
SECURITY_STATUS WINAPI FreeCredentialsHandle(PCredHandle phCredential)
Definition: wrapper.c:151

Referenced by do_authorization().

◆ destroy_cookies()

void destroy_cookies ( struct session session)

Definition at line 120 of file cookie.c.

121{
122 struct list *item, *next;
123 struct domain *domain;
124
126 {
127 domain = LIST_ENTRY( item, struct domain, entry );
129 }
130}
static unsigned __int64 next
Definition: rand_nt.c:6
#define LIST_FOR_EACH_SAFE(cursor, cursor2, list)
Definition: list.h:192
static void delete_domain(struct domain *domain)
Definition: cookie.c:104

Referenced by session_destroy().

◆ free_handle()

BOOL free_handle ( HINTERNET  hinternet)

Definition at line 123 of file handle.c.

124{
125 BOOL ret = FALSE;
126 ULONG_PTR handle = (ULONG_PTR)hinternet;
127 struct object_header *hdr = NULL;
128
130
131 if ((handle > 0) && (handle <= max_handles))
132 {
133 handle--;
134 if (handles[handle])
135 {
136 hdr = handles[handle];
137 TRACE( "destroying handle %Ix for object %p\n", handle + 1, hdr );
139 ret = TRUE;
140 }
141 }
142
144
145 if (hdr)
146 {
147 if (hdr->vtbl->handle_closing)
148 hdr->vtbl->handle_closing( hdr );
150 }
151
155
156 return ret;
157}
void release_object(struct object_header *hdr)
Definition: handle.c:71
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by pqInsert(), and WinHttpCloseHandle().

◆ grab_object()

◆ init_queue()

void init_queue ( struct queue queue)

Definition at line 137 of file request.c.

138{
142}
static void list_init(struct list_entry *head)
Definition: list.h:51
VOID WINAPI InitializeSRWLock(PSRWLOCK Lock)
Definition: sync.c:29
BOOL callback_running
SRWLOCK lock
struct list queued_tasks

Referenced by WinHttpOpenRequest(), and WinHttpWebSocketCompleteUpgrade().

◆ netconn_addref()

void netconn_addref ( struct netconn conn)

Definition at line 290 of file net.c.

291{
292 InterlockedIncrement( &conn->refs );
293}

Referenced by WinHttpWebSocketCompleteUpgrade().

◆ netconn_cancel_io()

void netconn_cancel_io ( struct netconn conn)

Definition at line 674 of file net.c.

675{
676 SOCKET socket = InterlockedExchange( (LONG *)&conn->socket, -1 );
677
679}
#define InterlockedExchange
Definition: armddk.h:54
#define closesocket
Definition: ncftp.h:477
long LONG
Definition: pedump.c:60
UINT_PTR SOCKET
Definition: winsock.h:41

Referenced by socket_handle_closing().

◆ netconn_create()

DWORD netconn_create ( struct hostdata host,
const struct sockaddr_storage sockaddr,
int  timeout,
struct netconn **  ret_conn 
)

Definition at line 212 of file net.c.

214{
215 struct netconn *conn;
216 unsigned int addr_len;
217 DWORD ret;
218
219#ifndef __REACTOS__
220 winsock_init();
221#endif
222
223 if (!(conn = calloc( 1, sizeof(*conn) ))) return ERROR_OUTOFMEMORY;
224 conn->refs = 1;
225 conn->host = host;
226 conn->sockaddr = *sockaddr;
227 if ((conn->socket = WSASocketW( sockaddr->ss_family, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED )) == -1)
228 {
230 WARN( "unable to create socket (%lu)\n", ret );
231 free( conn );
232 return ret;
233 }
235 ERR( "SetFileCompletionNotificationModes failed.\n" );
236
237 switch (conn->sockaddr.ss_family)
238 {
239 case AF_INET:
240 addr_len = sizeof(struct sockaddr_in);
241 break;
242 case AF_INET6:
243 addr_len = sizeof(struct sockaddr_in6);
244 break;
245 default:
246 ERR( "unhandled family %u\n", conn->sockaddr.ss_family );
247 free( conn );
249 }
250
251 if (timeout > 0) set_blocking( conn, FALSE );
252
253 if (!connect( conn->socket, (const struct sockaddr *)&conn->sockaddr, addr_len )) ret = ERROR_SUCCESS;
254 else
255 {
258 {
259 TIMEVAL timeval = { timeout / 1000, (timeout % 1000) * 1000 };
260 FD_SET set_read, set_error;
261 int res;
262
263 FD_ZERO( &set_read );
264 FD_SET( conn->socket, &set_read );
265 FD_ZERO( &set_error );
266 FD_SET( conn->socket, &set_error );
267 if ((res = select( conn->socket + 1, NULL, &set_read, &set_error, &timeval )) > 0)
268 {
269 if (FD_ISSET(conn->socket, &set_read)) ret = ERROR_SUCCESS;
270 else assert( FD_ISSET(conn->socket, &set_error) );
271 }
272 else if (!res) ret = ERROR_WINHTTP_TIMEOUT;
273 }
274 }
275
276 if (timeout > 0) set_blocking( conn, TRUE );
277
278 if (ret)
279 {
280 WARN( "unable to connect to host (%lu)\n", ret );
281 closesocket( conn->socket );
282 free( conn );
284 }
285
286 *ret_conn = conn;
287 return ERROR_SUCCESS;
288}
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define assert(_expr)
Definition: assert.h:32
static void winsock_init(void)
Definition: net.c:199
static void set_blocking(struct netconn *conn, BOOL blocking)
Definition: net.c:206
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
static void set_error(FCI_Int *fci, int oper, int err)
Definition: fci.c:196
GLuint res
Definition: glext.h:9613
BOOL WINAPI SetFileCompletionNotificationModes(IN HANDLE FileHandle, IN UCHAR Flags)
Definition: iocompl.c:31
#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
Definition: iocompl.c:22
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
SOCKET WSAAPI WSASocketW(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags)
Definition: socklife.c:490
Definition: winsock.h:60
struct hostdata * host
struct sockaddr_storage sockaddr
Definition: dhcpd.h:248
#define WSAEWOULDBLOCK
Definition: winerror.h:2851
#define WSAEINPROGRESS
Definition: winerror.h:2852
#define ERROR_WINHTTP_CANNOT_CONNECT
Definition: winhttp.h:247
#define ERROR_WINHTTP_TIMEOUT
Definition: winhttp.h:235
#define WSA_FLAG_OVERLAPPED
Definition: winsock2.h:460
#define FD_ISSET(fd, set)
Definition: winsock.h:94
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:131
#define FD_ZERO(set)
Definition: winsock.h:90
#define AF_INET6
Definition: winsock.h:363
#define FD_SET(fd, set)
Definition: winsock.h:83

Referenced by open_connection().

◆ netconn_get_certificate()

const void * netconn_get_certificate ( struct netconn conn)

Definition at line 850 of file net.c.

851{
852 const CERT_CONTEXT *ret;
854
855 if (!conn->secure) return NULL;
857 return res == SEC_E_OK ? ret : NULL;
858}
LONG SECURITY_STATUS
Definition: sspi.h:34
#define SECPKG_ATTR_REMOTE_CERT_CONTEXT
Definition: schannel.h:69
CtxtHandle ssl_ctx
#define SEC_E_OK
Definition: winerror.h:3450
SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
Definition: wrapper.c:535

Referenced by open_connection().

◆ netconn_get_cipher_strength()

int netconn_get_cipher_strength ( struct netconn conn)

Definition at line 860 of file net.c.

861{
864
865 if (!conn->secure) return 0;
867 if(res != SEC_E_OK)
868 WARN( "QueryContextAttributesW failed: %#lx\n", res );
869 return res == SEC_E_OK ? conn_info.dwCipherStrength : 0;
870}
#define SECPKG_ATTR_CONNECTION_INFO
Definition: schannel.h:76

Referenced by request_query_option().

◆ netconn_is_alive()

BOOL netconn_is_alive ( struct netconn netconn)

Definition at line 698 of file net.c.

699{
700 SIZE_T size;
701 int len;
702 char b;
703 DWORD err;
704 BOOL eof;
705
707 if (netconn->secure)
708 {
709 while (!netconn->peek_msg && !(err = read_ssl_chunk( netconn, NULL, 0, &size, &eof )) && !eof)
710 ;
711
712 TRACE( "checking secure connection, err %lu\n", err );
713
715 {
717 return TRUE;
718 }
720 {
722 return FALSE;
723 }
724 }
725 len = sock_recv( netconn->socket, &b, 1, MSG_PEEK );
728
729 return len == 1 || (len == -1 && err == WSAEWOULDBLOCK);
730}
static int eof(int fd)
Definition: io.h:21
static DWORD read_ssl_chunk(struct netconn *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof)
Definition: net.c:521
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:73
GLsizeiptr size
Definition: glext.h:5919
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define b
Definition: ke_i.h:79
#define err(...)
char * peek_msg
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define SEC_E_INCOMPLETE_MESSAGE
Definition: winerror.h:4332
#define MSG_PEEK
Definition: winsock.h:216

Referenced by open_connection().

◆ netconn_query_data_available()

ULONG netconn_query_data_available ( struct netconn conn)

Definition at line 681 of file net.c.

682{
683 return conn->secure ? conn->peek_len : 0;
684}
size_t peek_len

Referenced by query_data_ready().

◆ netconn_recv()

DWORD netconn_recv ( struct netconn conn,
void buf,
size_t  len,
int  flags,
int recvd 
)

Definition at line 618 of file net.c.

619{
620 *recvd = 0;
621 if (!len) return ERROR_SUCCESS;
622
623 if (conn->secure)
624 {
625 SIZE_T size;
626 DWORD res;
627 BOOL eof;
628
629 if (conn->peek_msg)
630 {
631 *recvd = min( len, conn->peek_len );
632 memcpy( buf, conn->peek_msg, *recvd );
633 conn->peek_len -= *recvd;
634 conn->peek_msg += *recvd;
635
636 if (conn->peek_len == 0)
637 {
638 free( conn->peek_msg_mem );
639 conn->peek_msg_mem = NULL;
640 conn->peek_msg = NULL;
641 }
642 /* check if we have enough data from the peek buffer */
643 if (!(flags & MSG_WAITALL) || *recvd == len) return ERROR_SUCCESS;
644 }
645 size = *recvd;
646
647 do
648 {
649 SIZE_T cread = 0;
650 if ((res = read_ssl_chunk( conn, (BYTE *)buf + size, len - size, &cread, &eof )))
651 {
652 WARN( "read_ssl_chunk failed: %lu\n", res );
653 if (!size) return res;
654 break;
655 }
656 if (eof)
657 {
658 TRACE("EOF\n");
659 break;
660 }
661 size += cread;
662
663 } while (!size || ((flags & MSG_WAITALL) && size < len));
664
665 TRACE( "received %Iu bytes\n", size );
666 *recvd = size;
667 return ERROR_SUCCESS;
668 }
669
670 if ((*recvd = sock_recv( conn->socket, buf, len, flags )) < 0) return WSAGetLastError();
671 return ERROR_SUCCESS;
672}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define min(a, b)
Definition: monoChain.cc:55
char * peek_msg_mem
unsigned char BYTE
Definition: xxhash.c:193

Referenced by read_more_data(), and receive_bytes().

◆ netconn_release()

void netconn_release ( struct netconn conn)

Definition at line 295 of file net.c.

296{
297 if (InterlockedDecrement( &conn->refs )) return;
298 TRACE( "Closing connection %p.\n", conn );
299 if (conn->secure)
300 {
301 free( conn->peek_msg_mem );
302 free(conn->ssl_read_buf);
303 free(conn->ssl_write_buf);
304 free(conn->extra_buf);
306 }
307 if (conn->socket != -1)
308 closesocket( conn->socket );
309 release_host( conn->host );
310 if (conn->port)
311 CloseHandle( conn->port );
312 free(conn);
313}
#define InterlockedDecrement
Definition: armddk.h:52
#define CloseHandle
Definition: compat.h:739
void release_host(struct hostdata *host)
Definition: request.c:1449
char * ssl_write_buf
char * extra_buf
char * ssl_read_buf
HANDLE port

Referenced by close_connection(), connection_collector(), finished_reading(), handle_redirect(), open_connection(), and socket_destroy().

◆ netconn_resolve()

DWORD netconn_resolve ( WCHAR hostname,
INTERNET_PORT  port,
struct sockaddr_storage addr,
int  timeout 
)

Definition at line 819 of file net.c.

820{
821 DWORD ret;
822
824 else
825 {
826 struct async_resolve *async;
827
828 if (!(async = create_async_resolve( hostname, port )))
829 return ERROR_OUTOFMEMORY;
830
831 InterlockedIncrement( &async->ref );
833 {
834 InterlockedDecrement( &async->ref );
835 async_resolve_release( async );
836 return GetLastError();
837 }
839 else
840 {
841 *addr = async->addr;
842 ret = async->result;
843 }
844 async_resolve_release( async );
845 }
846
847 return ret;
848}
char * hostname
Definition: ftp.c:88
BOOL WINAPI DECLSPEC_HOTPATCH TrySubmitThreadpoolCallback(PTP_SIMPLE_CALLBACK callback, PVOID userdata, TP_CALLBACK_ENVIRON *environment)
Definition: threadpool.c:9
USHORT port
Definition: uri.c:228
static void CALLBACK resolve_proc(TP_CALLBACK_INSTANCE *instance, void *ctx)
Definition: net.c:810
static void async_resolve_release(struct async_resolve *async)
Definition: net.c:801
static struct async_resolve * create_async_resolve(const WCHAR *hostname, INTERNET_PORT port)
Definition: net.c:780
static DWORD resolve_hostname(const WCHAR *name, INTERNET_PORT port, struct sockaddr_storage *sa)
Definition: net.c:732
GLenum const GLvoid * addr
Definition: glext.h:9621
LONG ref
Definition: net.c:772
DWORD result
Definition: net.c:776
struct sockaddr_storage addr
Definition: net.c:775
HANDLE done
Definition: net.c:777
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:383

Referenced by open_connection().

◆ netconn_secure_connect()

DWORD netconn_secure_connect ( struct netconn conn,
WCHAR hostname,
DWORD  security_flags,
CredHandle cred_handle,
BOOL  check_revocation 
)

Definition at line 315 of file net.c.

317{
318 SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}};
319 SecBufferDesc out_desc = {SECBUFFER_VERSION, 1, &out_buf}, in_desc = {SECBUFFER_VERSION, 2, in_bufs};
320 BYTE *read_buf;
321 SIZE_T read_buf_size = 2048;
322 ULONG attrs = 0;
325 const CERT_CONTEXT *cert;
328
331
332 if (!(read_buf = malloc( read_buf_size ))) return ERROR_OUTOFMEMORY;
333
334 memset( &ctx, 0, sizeof(ctx) );
335 status = InitializeSecurityContextW(cred_handle, NULL, hostname, isc_req_flags, 0, 0, NULL, 0,
336 &ctx, &out_desc, &attrs, NULL);
337
339
341 if(out_buf.cbBuffer) {
343
344 TRACE( "sending %lu bytes\n", out_buf.cbBuffer );
345
346 size = sock_send(conn->socket, out_buf.pvBuffer, out_buf.cbBuffer, NULL);
347 if(size != out_buf.cbBuffer) {
348 ERR("send failed\n");
350 break;
351 }
352
353 FreeContextBuffer(out_buf.pvBuffer);
354 out_buf.pvBuffer = NULL;
355 out_buf.cbBuffer = 0;
356 }
357
359 assert(in_bufs[1].cbBuffer < read_buf_size);
360
361 memmove(read_buf, (BYTE*)in_bufs[0].pvBuffer+in_bufs[0].cbBuffer-in_bufs[1].cbBuffer, in_bufs[1].cbBuffer);
362 in_bufs[0].cbBuffer = in_bufs[1].cbBuffer;
363 }
364
365 assert(in_bufs[0].BufferType == SECBUFFER_TOKEN);
366 in_bufs[1].BufferType = SECBUFFER_EMPTY;
367 in_bufs[1].cbBuffer = 0;
368 in_bufs[1].pvBuffer = NULL;
369
370 if(in_bufs[0].cbBuffer + 1024 > read_buf_size) {
371 BYTE *new_read_buf;
372
373 new_read_buf = realloc(read_buf, read_buf_size + 1024);
374 if(!new_read_buf) {
376 break;
377 }
378
379 in_bufs[0].pvBuffer = read_buf = new_read_buf;
380 read_buf_size += 1024;
381 }
382
383 size = sock_recv(conn->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0);
384 if(size < 1) {
386 break;
387 }
388
389 TRACE( "recv %Iu bytes\n", size );
390
391 in_bufs[0].cbBuffer += size;
392 in_bufs[0].pvBuffer = read_buf;
393 status = InitializeSecurityContextW(cred_handle, &ctx, hostname, isc_req_flags, 0, 0, &in_desc,
394 0, NULL, &out_desc, &attrs, NULL);
395 TRACE( "InitializeSecurityContext ret %#lx\n", status );
396
397 if(status == SEC_E_OK) {
398 if(in_bufs[1].BufferType == SECBUFFER_EXTRA)
399 FIXME("SECBUFFER_EXTRA not supported\n");
400
402 if(status != SEC_E_OK) {
403 WARN("Could not get sizes\n");
404 break;
405 }
406
408 if(status == SEC_E_OK) {
409 res = netconn_verify_cert(cert, hostname, security_flags, check_revocation);
411 if(res != ERROR_SUCCESS) {
412 WARN( "cert verify failed: %lu\n", res );
413 break;
414 }
415 }else {
416 WARN("Could not get cert\n");
417 break;
418 }
419
421 if(!conn->ssl_read_buf) {
423 break;
424 }
426 if(!conn->ssl_write_buf) {
428 break;
429 }
430 }
431 }
432
433 free(read_buf);
434
435 if(status != SEC_E_OK || res != ERROR_SUCCESS) {
436 WARN( "Failed to initialize security context: %#lx\n", status );
437 free(conn->ssl_read_buf);
438 conn->ssl_read_buf = NULL;
439 free(conn->ssl_write_buf);
440 conn->ssl_write_buf = NULL;
443 }
444
445
446 TRACE("established SSL connection\n");
447 conn->secure = TRUE;
448 conn->ssl_ctx = ctx;
449 return ERROR_SUCCESS;
450}
#define FIXME(fmt,...)
Definition: precomp.h:53
LONG_PTR SSIZE_T
Definition: basetsd.h:175
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
static int sock_send(int fd, const void *msg, size_t len, WSAOVERLAPPED *ovr)
Definition: net.c:35
static DWORD netconn_verify_cert(PCCERT_CONTEXT cert, WCHAR *server, DWORD security_flags, BOOL check_revocation)
Definition: net.c:84
#define read_buf
Definition: intsym.h:279
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static BYTE cert[]
Definition: msg.c:1374
static SecHandle cred_handle
#define ISC_REQ_MANUAL_CRED_VALIDATION
Definition: sspi.h:381
#define ISC_REQ_CONFIDENTIALITY
Definition: sspi.h:366
#define ISC_REQ_ALLOCATE_MEMORY
Definition: sspi.h:370
#define SECBUFFER_TOKEN
Definition: sspi.h:161
#define ISC_REQ_SEQUENCE_DETECT
Definition: sspi.h:365
#define ISC_REQ_REPLAY_DETECT
Definition: sspi.h:364
#define ISC_REQ_USE_SESSION_KEY
Definition: sspi.h:367
#define SECBUFFER_EXTRA
Definition: sspi.h:164
#define SECPKG_ATTR_STREAM_SIZES
Definition: sspi.h:525
#define SECBUFFER_VERSION
Definition: sspi.h:187
#define SECBUFFER_EMPTY
Definition: sspi.h:159
SECURITY_STATUS WINAPI FreeContextBuffer(PVOID pv)
Definition: sspi.c:699
ULONG cbBuffer
Definition: sspi.h:153
SecPkgContext_StreamSizes ssl_sizes
Definition: ps.c:97
#define SEC_I_CONTINUE_NEEDED
Definition: winerror.h:4324
#define ERROR_WINHTTP_SECURE_CHANNEL_ERROR
Definition: winhttp.h:265
SECURITY_STATUS WINAPI InitializeSecurityContextW(PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
Definition: wrapper.c:301

Referenced by open_connection().

◆ netconn_send()

DWORD netconn_send ( struct netconn conn,
const void msg,
size_t  len,
int sent,
WSAOVERLAPPED ovr 
)

Definition at line 479 of file net.c.

480{
481 DWORD err;
482
483 if (ovr && !conn->port)
484 {
485 if (!(conn->port = CreateIoCompletionPort( (HANDLE)(SOCKET)conn->socket, NULL, (ULONG_PTR)conn->socket, 0 )))
486 ERR( "Failed to create port.\n" );
487 }
488
489 if (conn->secure)
490 {
491 const BYTE *ptr = msg;
492 size_t chunk_size;
493 DWORD res;
494
495 *sent = 0;
496 while (len)
497 {
498 chunk_size = min( len, conn->ssl_sizes.cbMaximumMessage );
499 if ((res = send_ssl_chunk( conn, ptr, chunk_size, ovr )))
500 {
501 if (res == WSA_IO_PENDING) *sent += chunk_size;
502 return res;
503 }
504 *sent += chunk_size;
505 ptr += chunk_size;
506 len -= chunk_size;
507 }
508
509 return ERROR_SUCCESS;
510 }
511
512 if ((*sent = sock_send( conn->socket, msg, len, ovr )) < 0)
513 {
515 *sent = (err == WSA_IO_PENDING) ? len : 0;
516 return err;
517 }
518 return ERROR_SUCCESS;
519}
@ sent
Definition: SystemMenu.c:27
#define msg(x)
Definition: auth_time.c:54
static DWORD send_ssl_chunk(struct netconn *conn, const void *msg, size_t size, WSAOVERLAPPED *ovr)
Definition: net.c:452
HANDLE WINAPI CreateIoCompletionPort(IN HANDLE FileHandle, IN HANDLE ExistingCompletionPort, IN ULONG_PTR CompletionKey, IN DWORD NumberOfConcurrentThreads)
Definition: iocompl.c:65
static PVOID ptr
Definition: dispmode.c:27
#define WSA_IO_PENDING
Definition: winsock2.h:610

Referenced by secure_proxy_connect(), send_bytes(), send_request(), and write_data().

◆ netconn_set_timeout()

DWORD netconn_set_timeout ( struct netconn netconn,
BOOL  send,
int  value 
)

Definition at line 686 of file net.c.

687{
688 int opt = send ? SO_SNDTIMEO : SO_RCVTIMEO;
689 if (setsockopt( netconn->socket, SOL_SOCKET, opt, (void *)&value, sizeof(value) ) == -1)
690 {
692 WARN( "setsockopt failed (%lu)\n", err );
693 return err;
694 }
695 return ERROR_SUCCESS;
696}
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
Definition: pdh_main.c:96
#define SOL_SOCKET
Definition: winsock.h:392
#define SO_SNDTIMEO
Definition: winsock.h:186
#define SO_RCVTIMEO
Definition: winsock.h:187

Referenced by open_connection(), receive_response(), send_request(), socket_set_option(), WinHttpSetTimeouts(), and WinHttpWebSocketCompleteUpgrade().

◆ netconn_unload()

void netconn_unload ( void  )

Definition at line 182 of file net.c.

183{
185}
static BOOL winsock_loaded
Definition: net.c:180
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

Referenced by DllMain().

◆ netconn_wait_overlapped_result()

BOOL netconn_wait_overlapped_result ( struct netconn conn,
WSAOVERLAPPED ovr,
DWORD len 
)

Definition at line 54 of file net.c.

55{
56 OVERLAPPED *completion_ovr;
58
59 while (1)
60 {
61 if (!GetQueuedCompletionStatus( conn->port, len, &key, &completion_ovr, INFINITE ))
62 {
63 WARN( "GetQueuedCompletionStatus failed, err %lu.\n", GetLastError() );
64 return FALSE;
65 }
66 if (completion_ovr == (OVERLAPPED *)ovr && (key == conn->socket || conn->socket == -1))
67 break;
68 ERR( "Unexpected completion key %Ix, completion ovr %p, ovr %p.\n", key, completion_ovr, ovr );
69 }
70 return TRUE;
71}
#define INFINITE
Definition: serial.h:102
BOOL WINAPI GetQueuedCompletionStatus(IN HANDLE CompletionHandle, IN LPDWORD lpNumberOfBytesTransferred, OUT PULONG_PTR lpCompletionKey, OUT LPOVERLAPPED *lpOverlapped, IN DWORD dwMilliseconds)
Definition: iocompl.c:131
Definition: copy.c:22

Referenced by complete_send_frame().

◆ process_header()

DWORD process_header ( struct request request,
const WCHAR field,
const WCHAR value,
DWORD  flags,
BOOL  request_only 
)

Definition at line 424 of file request.c.

425{
426 int index;
427 struct header hdr;
428
429 TRACE( "%s: %s %#lx\n", debugstr_w(field), debugstr_w(value), flags );
430
431 if ((index = get_header_index( request, field, 0, request_only )) >= 0)
432 {
434 }
435
437 {
438 if (index >= 0)
439 {
441 if (!value || !value[0]) return ERROR_SUCCESS;
442 }
444
445 hdr.field = (LPWSTR)field;
446 hdr.value = (LPWSTR)value;
447 hdr.is_request = request_only;
448 return insert_header( request, &hdr );
449 }
450 else if (value)
451 {
452
454 index >= 0)
455 {
456 WCHAR *tmp;
457 int len, len_orig, len_value;
458 struct header *header = &request->headers[index];
459
460 len_orig = lstrlenW( header->value );
461 len_value = lstrlenW( value );
462
463 len = len_orig + len_value + 2;
464 if (!(tmp = realloc( header->value, (len + 1) * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
465 header->value = tmp;
466 header->value[len_orig++] = (flags & WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA) ? ',' : ';';
467 header->value[len_orig++] = ' ';
468
469 memcpy( &header->value[len_orig], value, len_value * sizeof(WCHAR) );
470 header->value[len] = 0;
471 return ERROR_SUCCESS;
472 }
473 else
474 {
475 hdr.field = (LPWSTR)field;
476 hdr.value = (LPWSTR)value;
477 hdr.is_request = request_only;
478 return insert_header( request, &hdr );
479 }
480 }
481
482 return ERROR_SUCCESS;
483}
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031
static void delete_header(struct request *request, DWORD index)
Definition: request.c:411
static DWORD insert_header(struct request *request, struct header *header)
Definition: request.c:390
unsigned int len
Definition: request.c:851
static int get_header_index(struct request *request, const WCHAR *field, int requested_index, BOOL request_only)
Definition: request.c:370
Definition: parser.c:44
struct header * headers
#define ERROR_WINHTTP_HEADER_ALREADY_EXISTS
Definition: winhttp.h:263
#define WINHTTP_ADDREQ_FLAG_ADD_IF_NEW
Definition: winhttp.h:91
#define WINHTTP_ADDREQ_FLAG_REPLACE
Definition: winhttp.h:96
#define ERROR_WINHTTP_HEADER_NOT_FOUND
Definition: winhttp.h:259
#define WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
Definition: winhttp.h:93
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by add_accept_types_header(), add_host_header(), add_request_headers(), add_websocket_key_header(), do_authorization(), handle_passport_redirect(), read_reply(), and send_request().

◆ release_host()

void release_host ( struct hostdata host)

Definition at line 1449 of file request.c.

1450{
1451 LONG ref;
1452
1454 if (!(ref = --host->ref)) list_remove( &host->entry );
1456 if (ref) return;
1457
1458 assert( list_empty( &host->connections ) );
1459 free( host->hostname );
1460 free( host );
1461}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static int list_empty(struct list_entry *head)
Definition: list.h:58
static CRITICAL_SECTION connection_pool_cs
Definition: request.c:1438
Definition: txthost.c:37
LONG ref
Definition: txthost.c:39
Definition: send.c:48

Referenced by netconn_release(), and open_connection().

◆ release_object()

void release_object ( struct object_header hdr)

◆ release_typelib()

void release_typelib ( void  )

Definition at line 159 of file apps.c.

160{
161 unsigned i;
162
163 for (i = 0; i < ARRAY_SIZE(typeinfo); i++)
164 if (typeinfo[i])
165 ITypeInfo_Release(typeinfo[i]);
166
167 if (typelib)
168 ITypeLib_Release(typelib);
169}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by DllMain(), and process_detach().

◆ send_callback()

◆ set_cookies()

BOOL set_cookies ( struct request request,
const WCHAR cookies 
)

Definition at line 263 of file cookie.c.

264{
265 BOOL ret = FALSE;
266 WCHAR *buffer, *p;
267 WCHAR *cookie_domain = NULL, *cookie_path = NULL;
268 struct attr *attr, *domain = NULL, *path = NULL;
269 struct session *session = request->connect->session;
270 struct cookie *cookie;
271 int len, used;
272
273 len = lstrlenW( cookies );
274 if (!(buffer = malloc( (len + 1) * sizeof(WCHAR) ))) return FALSE;
276
277 p = buffer;
278 while (*p && *p != ';') p++;
279 if (*p == ';') *p++ = 0;
280 if (!(cookie = parse_cookie( buffer )))
281 {
282 free( buffer );
283 return FALSE;
284 }
285 len = lstrlenW( p );
286 while (len && (attr = parse_attr( p, &used )))
287 {
288 if (!wcsicmp( attr->name, L"domain" ))
289 {
290 domain = attr;
291 cookie_domain = attr->value;
292 }
293 else if (!wcsicmp( attr->name, L"path" ))
294 {
295 path = attr;
296 cookie_path = attr->value;
297 }
298 else
299 {
300 FIXME( "unhandled attribute %s\n", debugstr_w(attr->name) );
301 free_attr( attr );
302 }
303 len -= used;
304 p += used;
305 }
306 if (!cookie_domain && !(cookie_domain = wcsdup( request->connect->servername ))) goto end;
307 if (!cookie_path && !(cookie_path = wcsdup( request->path ))) goto end;
308
309 if ((p = wcsrchr( cookie_path, '/' )) && p != cookie_path) *p = 0;
310 ret = add_cookie( session, cookie, cookie_domain, cookie_path );
311
312end:
313 if (!ret) free_cookie( cookie );
314 if (domain) free_attr( domain );
315 else free( cookie_domain );
316 if (path) free_attr( path );
317 else free( cookie_path );
318 free( buffer );
319 return ret;
320}
static int used
Definition: adh-main.c:39
#define wcsrchr
Definition: compat.h:16
#define wcsicmp
Definition: compat.h:15
static wchar_t * wcsdup(const wchar_t *str)
Definition: string.h:94
#define L(x)
Definition: resources.c:13
GLuint buffer
Definition: glext.h:5915
static CookieInternal * cookies
Definition: msctf.cpp:37
Definition: cookie.c:202
WCHAR * value
Definition: cookie.c:204
WCHAR * name
Definition: cookie.c:203
static struct attr * parse_attr(const WCHAR *str, int *used)
Definition: cookie.c:215
static struct cookie * parse_cookie(const WCHAR *string)
Definition: cookie.c:162
static BOOL add_cookie(struct session *session, struct cookie *cookie, WCHAR *domain_name, WCHAR *path)
Definition: cookie.c:132
static void free_attr(struct attr *attr)
Definition: cookie.c:207
void free_cookie(void)
Definition: cookie.c:1269

Referenced by record_cookies().

◆ set_server_for_hostname()

BOOL set_server_for_hostname ( struct connect connect,
const WCHAR server,
INTERNET_PORT  port 
)

Definition at line 532 of file session.c.

533{
534 struct session *session = connect->session;
535 BOOL ret = TRUE;
536
538 {
539 LPCWSTR colon;
540
541 if ((colon = wcschr( session->proxy_server, ':' )))
542 {
544 session->proxy_server, colon - session->proxy_server - 1 ))
545 {
548 if (!(connect->servername = malloc( (colon - session->proxy_server + 1) * sizeof(WCHAR) )))
549 {
550 ret = FALSE;
551 goto end;
552 }
554 connect->servername[colon - session->proxy_server] = 0;
555 if (*(colon + 1))
556 connect->serverport = wcstol( colon + 1, NULL, 10 );
557 else
559 }
560 }
561 else
562 {
564 {
568 {
569 ret = FALSE;
570 goto end;
571 }
573 }
574 }
575 }
576 else if (server)
577 {
580 if (!(connect->servername = wcsdup( server )))
581 {
582 ret = FALSE;
583 goto end;
584 }
586 }
587end:
588 return ret;
589}
#define wcschr
Definition: compat.h:17
#define wcsnicmp
Definition: compat.h:14
_ACRTIMP __msvcrt_long __cdecl wcstol(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2747
static BOOL should_bypass_proxy(struct session *session, LPCWSTR server)
Definition: session.c:501
struct session * session
WCHAR * servername
INTERNET_PORT serverport
WCHAR * proxy_server
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define INTERNET_DEFAULT_PORT
Definition: winhttp.h:40
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by handle_redirect(), and WinHttpConnect().

◆ stop_queue()

void stop_queue ( struct queue queue)

Definition at line 144 of file request.c.

145{
147 TRACE("stopped %p\n", queue);
148}

Referenced by request_destroy(), and socket_destroy().

◆ strdupAW()

static WCHAR * strdupAW ( const char src)
inlinestatic

Definition at line 446 of file winhttp_private.h.

447{
448 WCHAR *dst = NULL;
449 if (src)
450 {
451 int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
452 if ((dst = malloc( len * sizeof(WCHAR) )))
453 MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
454 }
455 return dst;
456}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

◆ strdupWA()

static char * strdupWA ( const WCHAR src)
inlinestatic

Definition at line 458 of file winhttp_private.h.

459{
460 char *dst = NULL;
461 if (src)
462 {
463 int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
464 if ((dst = malloc( len )))
466 }
467 return dst;
468}
#define WideCharToMultiByte
Definition: compat.h:111

◆ WinHttpRequest_create()

HRESULT WinHttpRequest_create ( void **  obj)

Definition at line 6155 of file request.c.

6156{
6157 struct winhttp_request *request;
6158
6159 TRACE("%p\n", obj);
6160
6161 if (!(request = calloc( 1, sizeof(*request) ))) return E_OUTOFMEMORY;
6162 request->IWinHttpRequest_iface.lpVtbl = &winhttp_request_vtbl;
6163 request->refs = 1;
6165 request->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": winhttp_request.cs");
6167
6168 *obj = &request->IWinHttpRequest_iface;
6169 TRACE("returning iface %p\n", *obj);
6170 return S_OK;
6171}
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
#define S_OK
Definition: intsafe.h:52
static const struct IWinHttpRequestVtbl winhttp_request_vtbl
Definition: request.c:6125
static void initialize_request(struct winhttp_request *request)
Definition: request.c:4999
#define DWORD_PTR
Definition: treelist.c:76
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1156

Variable Documentation

◆ winhttp_instance

HINSTANCE winhttp_instance
extern

Definition at line 33 of file main.c.

Referenced by cache_connection(), connection_collector(), and DllMain().