2008-09-07 08:21:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Hans Leidekker for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WINE_WINHTTP_PRIVATE_H_
|
|
|
|
#define _WINE_WINHTTP_PRIVATE_H_
|
|
|
|
|
2014-01-01 21:42:31 +00:00
|
|
|
#include <wine/config.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#define _INC_WINDOWS
|
|
|
|
#define COM_NO_WINDOWS_H
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <objbase.h>
|
|
|
|
#include <oleauto.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winhttp.h>
|
2008-09-07 08:21:35 +00:00
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <wine/list.h>
|
|
|
|
#include <wine/unicode.h>
|
2008-09-07 08:21:35 +00:00
|
|
|
|
2010-10-09 21:52:25 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
2008-09-07 08:21:35 +00:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
# include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#if defined(__MINGW32__) || defined (_MSC_VER)
|
2009-06-07 12:32:05 +00:00
|
|
|
# include <ws2tcpip.h>
|
2008-09-07 08:21:35 +00:00
|
|
|
#else
|
2009-06-07 12:32:05 +00:00
|
|
|
# define closesocket close
|
|
|
|
# define ioctlsocket ioctl
|
|
|
|
#endif
|
2014-01-01 21:42:31 +00:00
|
|
|
|
2013-05-21 20:06:46 +00:00
|
|
|
#include <sspi.h>
|
2009-06-07 12:32:05 +00:00
|
|
|
|
2014-01-01 21:42:31 +00:00
|
|
|
#include <wine/debug.h>
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
|
|
|
|
|
2009-06-07 12:32:05 +00:00
|
|
|
static const WCHAR getW[] = {'G','E','T',0};
|
|
|
|
static const WCHAR postW[] = {'P','O','S','T',0};
|
2012-07-14 16:13:51 +00:00
|
|
|
static const WCHAR headW[] = {'H','E','A','D',0};
|
2009-06-07 12:32:05 +00:00
|
|
|
static const WCHAR slashW[] = {'/',0};
|
|
|
|
static const WCHAR http1_0[] = {'H','T','T','P','/','1','.','0',0};
|
|
|
|
static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
|
2013-09-28 15:23:56 +00:00
|
|
|
static const WCHAR chunkedW[] = {'c','h','u','n','k','e','d',0};
|
2008-09-07 08:21:35 +00:00
|
|
|
|
|
|
|
typedef struct _object_header_t object_header_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void (*destroy)( object_header_t * );
|
|
|
|
BOOL (*query_option)( object_header_t *, DWORD, void *, DWORD * );
|
|
|
|
BOOL (*set_option)( object_header_t *, DWORD, void *, DWORD );
|
|
|
|
} object_vtbl_t;
|
|
|
|
|
|
|
|
struct _object_header_t
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
HINTERNET handle;
|
|
|
|
const object_vtbl_t *vtbl;
|
|
|
|
DWORD flags;
|
|
|
|
DWORD disable_flags;
|
|
|
|
DWORD logon_policy;
|
|
|
|
DWORD redirect_policy;
|
|
|
|
DWORD error;
|
|
|
|
DWORD_PTR context;
|
|
|
|
LONG refs;
|
|
|
|
WINHTTP_STATUS_CALLBACK callback;
|
|
|
|
DWORD notify_mask;
|
|
|
|
struct list entry;
|
|
|
|
struct list children;
|
|
|
|
};
|
|
|
|
|
2009-06-07 12:32:05 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
WCHAR *name;
|
|
|
|
struct list cookies;
|
|
|
|
} domain_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
WCHAR *name;
|
|
|
|
WCHAR *value;
|
|
|
|
WCHAR *path;
|
|
|
|
} cookie_t;
|
|
|
|
|
2017-09-24 11:17:43 +00:00
|
|
|
typedef struct {
|
|
|
|
struct list entry;
|
|
|
|
LONG ref;
|
|
|
|
WCHAR *hostname;
|
|
|
|
INTERNET_PORT port;
|
|
|
|
BOOL secure;
|
|
|
|
struct list connections;
|
|
|
|
} hostdata_t;
|
|
|
|
|
2008-09-07 08:21:35 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
object_header_t hdr;
|
|
|
|
LPWSTR agent;
|
|
|
|
DWORD access;
|
2010-10-09 21:52:25 +00:00
|
|
|
int resolve_timeout;
|
|
|
|
int connect_timeout;
|
|
|
|
int send_timeout;
|
|
|
|
int recv_timeout;
|
2008-09-07 08:21:35 +00:00
|
|
|
LPWSTR proxy_server;
|
|
|
|
LPWSTR proxy_bypass;
|
|
|
|
LPWSTR proxy_username;
|
|
|
|
LPWSTR proxy_password;
|
2009-06-07 12:32:05 +00:00
|
|
|
struct list cookie_cache;
|
2015-11-22 10:13:38 +00:00
|
|
|
HANDLE unload_event;
|
2008-09-07 08:21:35 +00:00
|
|
|
} session_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
object_header_t hdr;
|
|
|
|
session_t *session;
|
|
|
|
LPWSTR hostname; /* final destination of the request */
|
|
|
|
LPWSTR servername; /* name of the server we directly connect to */
|
|
|
|
LPWSTR username;
|
|
|
|
LPWSTR password;
|
|
|
|
INTERNET_PORT hostport;
|
|
|
|
INTERNET_PORT serverport;
|
2010-10-09 21:52:25 +00:00
|
|
|
struct sockaddr_storage sockaddr;
|
2012-07-14 16:13:51 +00:00
|
|
|
BOOL resolved;
|
2008-09-07 08:21:35 +00:00
|
|
|
} connect_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-09-24 11:17:43 +00:00
|
|
|
struct list entry;
|
2008-09-07 08:21:35 +00:00
|
|
|
int socket;
|
2017-09-24 11:17:43 +00:00
|
|
|
struct sockaddr_storage sockaddr;
|
2008-09-07 08:21:35 +00:00
|
|
|
BOOL secure; /* SSL active on connection? */
|
2017-09-24 11:17:43 +00:00
|
|
|
hostdata_t *host;
|
|
|
|
ULONGLONG keep_until;
|
2013-05-21 20:06:46 +00:00
|
|
|
CtxtHandle ssl_ctx;
|
|
|
|
SecPkgContext_StreamSizes ssl_sizes;
|
|
|
|
char *ssl_buf;
|
|
|
|
char *extra_buf;
|
|
|
|
size_t extra_len;
|
2008-09-07 08:21:35 +00:00
|
|
|
char *peek_msg;
|
|
|
|
char *peek_msg_mem;
|
|
|
|
size_t peek_len;
|
|
|
|
} netconn_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPWSTR field;
|
|
|
|
LPWSTR value;
|
|
|
|
BOOL is_request; /* part of request headers? */
|
|
|
|
} header_t;
|
|
|
|
|
2015-07-22 19:39:23 +00:00
|
|
|
enum auth_target
|
|
|
|
{
|
|
|
|
TARGET_INVALID = -1,
|
|
|
|
TARGET_SERVER,
|
|
|
|
TARGET_PROXY,
|
|
|
|
TARGET_MAX
|
|
|
|
};
|
|
|
|
|
2013-09-28 15:23:56 +00:00
|
|
|
enum auth_scheme
|
|
|
|
{
|
|
|
|
SCHEME_INVALID = -1,
|
|
|
|
SCHEME_BASIC,
|
|
|
|
SCHEME_NTLM,
|
|
|
|
SCHEME_PASSPORT,
|
|
|
|
SCHEME_DIGEST,
|
2015-07-22 19:39:23 +00:00
|
|
|
SCHEME_NEGOTIATE,
|
|
|
|
SCHEME_MAX
|
2013-09-28 15:23:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct authinfo
|
|
|
|
{
|
|
|
|
enum auth_scheme scheme;
|
|
|
|
CredHandle cred;
|
|
|
|
CtxtHandle ctx;
|
|
|
|
TimeStamp exp;
|
|
|
|
ULONG attr;
|
|
|
|
ULONG max_token;
|
|
|
|
char *data;
|
|
|
|
unsigned int data_len;
|
|
|
|
BOOL finished; /* finished authenticating */
|
|
|
|
};
|
|
|
|
|
2008-09-07 08:21:35 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
object_header_t hdr;
|
|
|
|
connect_t *connect;
|
|
|
|
LPWSTR verb;
|
|
|
|
LPWSTR path;
|
|
|
|
LPWSTR version;
|
|
|
|
LPWSTR raw_headers;
|
2013-09-28 15:23:56 +00:00
|
|
|
void *optional;
|
|
|
|
DWORD optional_len;
|
2017-09-24 11:17:43 +00:00
|
|
|
netconn_t *netconn;
|
|
|
|
DWORD security_flags;
|
2010-10-09 21:52:25 +00:00
|
|
|
int resolve_timeout;
|
|
|
|
int connect_timeout;
|
|
|
|
int send_timeout;
|
|
|
|
int recv_timeout;
|
2008-09-07 08:21:35 +00:00
|
|
|
LPWSTR status_text;
|
2014-04-26 17:34:51 +00:00
|
|
|
DWORD content_length; /* total number of bytes to be read */
|
2008-09-07 08:21:35 +00:00
|
|
|
DWORD content_read; /* bytes read so far */
|
2013-09-28 15:23:56 +00:00
|
|
|
BOOL read_chunked; /* are we reading in chunked mode? */
|
2014-04-26 17:34:51 +00:00
|
|
|
BOOL read_chunked_eof; /* end of stream in chunked mode */
|
|
|
|
BOOL read_chunked_size; /* chunk size remaining */
|
2013-09-28 15:23:56 +00:00
|
|
|
DWORD read_pos; /* current read position in read_buf */
|
|
|
|
DWORD read_size; /* valid data size in read_buf */
|
2015-04-09 13:29:04 +00:00
|
|
|
char read_buf[8192]; /* buffer for already read but not returned data */
|
2008-09-07 08:21:35 +00:00
|
|
|
header_t *headers;
|
|
|
|
DWORD num_headers;
|
2013-09-28 15:23:56 +00:00
|
|
|
struct authinfo *authinfo;
|
|
|
|
struct authinfo *proxy_authinfo;
|
2015-04-09 13:29:04 +00:00
|
|
|
HANDLE task_wait;
|
|
|
|
HANDLE task_cancel;
|
|
|
|
HANDLE task_thread;
|
|
|
|
struct list task_queue;
|
|
|
|
CRITICAL_SECTION task_cs;
|
2015-07-22 19:39:23 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
WCHAR *username;
|
|
|
|
WCHAR *password;
|
|
|
|
} creds[TARGET_MAX][SCHEME_MAX];
|
2008-09-07 08:21:35 +00:00
|
|
|
} request_t;
|
|
|
|
|
2009-06-07 12:32:05 +00:00
|
|
|
typedef struct _task_header_t task_header_t;
|
|
|
|
|
|
|
|
struct _task_header_t
|
|
|
|
{
|
2015-04-09 13:29:04 +00:00
|
|
|
struct list entry;
|
2009-06-07 12:32:05 +00:00
|
|
|
request_t *request;
|
|
|
|
void (*proc)( task_header_t * );
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
task_header_t hdr;
|
|
|
|
LPWSTR headers;
|
|
|
|
DWORD headers_len;
|
|
|
|
LPVOID optional;
|
|
|
|
DWORD optional_len;
|
|
|
|
DWORD total_len;
|
|
|
|
DWORD_PTR context;
|
|
|
|
} send_request_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
task_header_t hdr;
|
|
|
|
} receive_response_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
task_header_t hdr;
|
|
|
|
LPDWORD available;
|
|
|
|
} query_data_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
task_header_t hdr;
|
|
|
|
LPVOID buffer;
|
|
|
|
DWORD to_read;
|
|
|
|
LPDWORD read;
|
|
|
|
} read_data_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
task_header_t hdr;
|
|
|
|
LPCVOID buffer;
|
|
|
|
DWORD to_write;
|
|
|
|
LPDWORD written;
|
|
|
|
} write_data_t;
|
|
|
|
|
2011-06-05 21:39:34 +00:00
|
|
|
object_header_t *addref_object( object_header_t * ) DECLSPEC_HIDDEN;
|
|
|
|
object_header_t *grab_object( HINTERNET ) DECLSPEC_HIDDEN;
|
|
|
|
void release_object( object_header_t * ) DECLSPEC_HIDDEN;
|
|
|
|
HINTERNET alloc_handle( object_header_t * ) DECLSPEC_HIDDEN;
|
|
|
|
BOOL free_handle( HINTERNET ) DECLSPEC_HIDDEN;
|
2008-09-07 08:21:35 +00:00
|
|
|
|
2011-06-05 21:39:34 +00:00
|
|
|
void set_last_error( DWORD ) DECLSPEC_HIDDEN;
|
|
|
|
DWORD get_last_error( void ) DECLSPEC_HIDDEN;
|
|
|
|
void send_callback( object_header_t *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN;
|
|
|
|
void close_connection( request_t * ) DECLSPEC_HIDDEN;
|
2008-09-07 08:21:35 +00:00
|
|
|
|
2011-06-05 21:39:34 +00:00
|
|
|
BOOL netconn_close( netconn_t * ) DECLSPEC_HIDDEN;
|
2017-09-24 11:17:43 +00:00
|
|
|
netconn_t *netconn_create( hostdata_t *, const struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
|
2011-06-05 21:39:34 +00:00
|
|
|
void netconn_unload( void ) DECLSPEC_HIDDEN;
|
2014-04-26 17:34:51 +00:00
|
|
|
ULONG netconn_query_data_available( netconn_t * ) DECLSPEC_HIDDEN;
|
2011-06-05 21:39:34 +00:00
|
|
|
BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
|
2017-09-24 11:17:43 +00:00
|
|
|
BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
|
|
|
|
BOOL netconn_secure_connect( netconn_t *, WCHAR *, DWORD ) DECLSPEC_HIDDEN;
|
2013-09-28 15:23:56 +00:00
|
|
|
BOOL netconn_send( netconn_t *, const void *, size_t, int * ) DECLSPEC_HIDDEN;
|
2011-06-05 21:39:34 +00:00
|
|
|
DWORD netconn_set_timeout( netconn_t *, BOOL, int ) DECLSPEC_HIDDEN;
|
2017-09-24 11:17:43 +00:00
|
|
|
BOOL netconn_is_alive( netconn_t * ) DECLSPEC_HIDDEN;
|
2011-06-05 21:39:34 +00:00
|
|
|
const void *netconn_get_certificate( netconn_t * ) DECLSPEC_HIDDEN;
|
|
|
|
int netconn_get_cipher_strength( netconn_t * ) DECLSPEC_HIDDEN;
|
2009-06-07 12:32:05 +00:00
|
|
|
|
2011-06-05 21:39:34 +00:00
|
|
|
BOOL set_cookies( request_t *, const WCHAR * ) DECLSPEC_HIDDEN;
|
|
|
|
BOOL add_cookie_headers( request_t * ) DECLSPEC_HIDDEN;
|
|
|
|
BOOL add_request_headers( request_t *, LPCWSTR, DWORD, DWORD ) DECLSPEC_HIDDEN;
|
|
|
|
void delete_domain( domain_t * ) DECLSPEC_HIDDEN;
|
2013-09-28 15:23:56 +00:00
|
|
|
BOOL set_server_for_hostname( connect_t *, LPCWSTR, INTERNET_PORT ) DECLSPEC_HIDDEN;
|
|
|
|
void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
|
2008-09-07 08:21:35 +00:00
|
|
|
|
2017-09-24 11:17:43 +00:00
|
|
|
void release_host( hostdata_t *host ) DECLSPEC_HIDDEN;
|
|
|
|
|
2017-03-19 17:04:32 +00:00
|
|
|
BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) DECLSPEC_HIDDEN;
|
|
|
|
|
2014-04-26 17:34:51 +00:00
|
|
|
extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
|
2015-04-09 13:29:04 +00:00
|
|
|
void release_typelib( void ) DECLSPEC_HIDDEN;
|
2012-07-14 16:13:51 +00:00
|
|
|
|
2017-03-19 17:04:32 +00:00
|
|
|
static inline void* __WINE_ALLOC_SIZE(1) heap_alloc( SIZE_T size )
|
2008-09-07 08:21:35 +00:00
|
|
|
{
|
|
|
|
return HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
}
|
|
|
|
|
2017-03-19 17:04:32 +00:00
|
|
|
static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero( SIZE_T size )
|
2008-09-07 08:21:35 +00:00
|
|
|
{
|
|
|
|
return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
|
|
|
|
}
|
|
|
|
|
2017-03-19 17:04:32 +00:00
|
|
|
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc( LPVOID mem, SIZE_T size )
|
2008-09-07 08:21:35 +00:00
|
|
|
{
|
|
|
|
return HeapReAlloc( GetProcessHeap(), 0, mem, size );
|
|
|
|
}
|
|
|
|
|
2017-03-19 17:04:32 +00:00
|
|
|
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
|
2008-09-07 08:21:35 +00:00
|
|
|
{
|
|
|
|
return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL heap_free( LPVOID mem )
|
|
|
|
{
|
|
|
|
return HeapFree( GetProcessHeap(), 0, mem );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline WCHAR *strdupW( const WCHAR *src )
|
|
|
|
{
|
|
|
|
WCHAR *dst;
|
|
|
|
|
|
|
|
if (!src) return NULL;
|
|
|
|
dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) );
|
|
|
|
if (dst) strcpyW( dst, src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline WCHAR *strdupAW( const char *src )
|
|
|
|
{
|
|
|
|
WCHAR *dst = NULL;
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
|
|
|
|
if ((dst = heap_alloc( len * sizeof(WCHAR) )))
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *strdupWA( const WCHAR *src )
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
|
|
|
|
if ((dst = heap_alloc( len )))
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2016-11-23 11:59:10 +00:00
|
|
|
static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
int len = WideCharToMultiByte( CP_ACP, 0, src, size, NULL, 0, NULL, NULL ) + 1;
|
|
|
|
if ((dst = heap_alloc( len )))
|
|
|
|
{
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, src, len, dst, size, NULL, NULL );
|
|
|
|
dst[len - 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2017-09-24 11:17:43 +00:00
|
|
|
extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
|
|
|
|
|
2008-09-07 08:21:35 +00:00
|
|
|
#endif /* _WINE_WINHTTP_PRIVATE_H_ */
|