winhttp_private.h 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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_

22 23 24 25
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif

26
#include "wine/list.h"
27
#include "wine/unicode.h"
28

29
#include <sys/types.h>
30 31 32
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
33 34 35
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
36 37 38
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
39 40
#if defined(__MINGW32__) || defined (_MSC_VER)
# include <ws2tcpip.h>
41 42 43
#else
# define closesocket close
# define ioctlsocket ioctl
44
#endif
45

46
#include "ole2.h"
47
#include "sspi.h"
48

49 50
static const WCHAR getW[]    = {'G','E','T',0};
static const WCHAR postW[]   = {'P','O','S','T',0};
51
static const WCHAR headW[]   = {'H','E','A','D',0};
52
static const WCHAR slashW[]  = {'/',0};
53
static const WCHAR http1_0[] = {'H','T','T','P','/','1','.','0',0};
54
static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
55
static const WCHAR chunkedW[] = {'c','h','u','n','k','e','d',0};
56

57 58 59 60 61
typedef struct _object_header_t object_header_t;

typedef struct
{
    void (*destroy)( object_header_t * );
62
    BOOL (*query_option)( object_header_t *, DWORD, void *, DWORD * );
63 64 65 66 67 68 69 70 71
    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;
72 73 74
    DWORD disable_flags;
    DWORD logon_policy;
    DWORD redirect_policy;
75 76 77 78 79 80 81 82 83
    DWORD error;
    DWORD_PTR context;
    LONG refs;
    WINHTTP_STATUS_CALLBACK callback;
    DWORD notify_mask;
    struct list entry;
    struct list children;
};

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
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;

99 100 101 102 103 104
typedef struct {
    struct list entry;
    LONG ref;
    WCHAR *hostname;
    INTERNET_PORT port;
    BOOL secure;
105
    struct list connections;
106
} hostdata_t;
107

108 109 110 111 112
typedef struct
{
    object_header_t hdr;
    LPWSTR agent;
    DWORD access;
113
    int resolve_timeout;
114 115 116
    int connect_timeout;
    int send_timeout;
    int recv_timeout;
117 118 119 120
    LPWSTR proxy_server;
    LPWSTR proxy_bypass;
    LPWSTR proxy_username;
    LPWSTR proxy_password;
121
    struct list cookie_cache;
122
    HANDLE unload_event;
123 124
    CredHandle cred_handle;
    BOOL cred_handle_initialized;
125
    DWORD secure_protocols;
126 127
} session_t;

128 129 130 131 132 133 134 135 136 137
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;
138
    struct sockaddr_storage sockaddr;
139
    BOOL resolved;
140 141
} connect_t;

142 143
typedef struct
{
144
    struct list entry;
145
    int socket;
146
    struct sockaddr_storage sockaddr;
147
    BOOL secure; /* SSL active on connection? */
148
    hostdata_t *host;
149
    ULONGLONG keep_until;
150 151
    CtxtHandle ssl_ctx;
    SecPkgContext_StreamSizes ssl_sizes;
152
    char *ssl_buf;
153 154
    char *extra_buf;
    size_t extra_len;
155 156 157 158 159 160 161 162 163
    char *peek_msg;
    char *peek_msg_mem;
    size_t peek_len;
} netconn_t;

typedef struct
{
    LPWSTR field;
    LPWSTR value;
164
    BOOL is_request; /* part of request headers? */
165 166
} header_t;

167 168 169 170 171 172 173 174
enum auth_target
{
    TARGET_INVALID = -1,
    TARGET_SERVER,
    TARGET_PROXY,
    TARGET_MAX
};

175 176 177 178 179 180 181
enum auth_scheme
{
    SCHEME_INVALID = -1,
    SCHEME_BASIC,
    SCHEME_NTLM,
    SCHEME_PASSPORT,
    SCHEME_DIGEST,
182 183
    SCHEME_NEGOTIATE,
    SCHEME_MAX
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
};

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 */
};

199 200 201 202 203 204 205 206
typedef struct
{
    object_header_t hdr;
    connect_t *connect;
    LPWSTR verb;
    LPWSTR path;
    LPWSTR version;
    LPWSTR raw_headers;
207 208
    void *optional;
    DWORD optional_len;
209
    netconn_t *netconn;
210
    DWORD security_flags;
211
    int resolve_timeout;
212
    int connect_timeout;
213 214
    int send_timeout;
    int recv_timeout;
215
    LPWSTR 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 220
    BOOL  read_chunked_eof;  /* end of stream in chunked mode */
    BOOL  read_chunked_size; /* chunk size remaining */
221 222
    DWORD read_pos;       /* current read position in read_buf */
    DWORD read_size;      /* valid data size in read_buf */
223
    char  read_buf[8192]; /* buffer for already read but not returned data */
224 225
    header_t *headers;
    DWORD num_headers;
226 227
    WCHAR **accept_types;
    DWORD num_accept_types;
228 229
    struct authinfo *authinfo;
    struct authinfo *proxy_authinfo;
230 231 232 233 234
    HANDLE task_wait;
    HANDLE task_cancel;
    HANDLE task_thread;
    struct list task_queue;
    CRITICAL_SECTION task_cs;
235 236 237 238 239
    struct
    {
        WCHAR *username;
        WCHAR *password;
    } creds[TARGET_MAX][SCHEME_MAX];
240 241
} request_t;

242 243 244 245
typedef struct _task_header_t task_header_t;

struct _task_header_t
{
246
    struct list entry;
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
    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;

289 290 291 292 293
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;
294

295 296 297 298
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;
299

300
BOOL netconn_close( netconn_t * ) DECLSPEC_HIDDEN;
301
netconn_t *netconn_create( hostdata_t *, const struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
302
void netconn_unload( void ) DECLSPEC_HIDDEN;
303
ULONG netconn_query_data_available( netconn_t * ) DECLSPEC_HIDDEN;
304
BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
305
BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
306
BOOL netconn_secure_connect( netconn_t *, WCHAR *, DWORD, CredHandle * ) DECLSPEC_HIDDEN;
307
BOOL netconn_send( netconn_t *, const void *, size_t, int * ) DECLSPEC_HIDDEN;
308
DWORD netconn_set_timeout( netconn_t *, BOOL, int ) DECLSPEC_HIDDEN;
309
BOOL netconn_is_alive( netconn_t * ) DECLSPEC_HIDDEN;
310 311
const void *netconn_get_certificate( netconn_t * ) DECLSPEC_HIDDEN;
int netconn_get_cipher_strength( netconn_t * ) DECLSPEC_HIDDEN;
312

313 314 315 316
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;
317 318
BOOL set_server_for_hostname( connect_t *, LPCWSTR, INTERNET_PORT ) DECLSPEC_HIDDEN;
void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
319

320
void release_host( hostdata_t *host ) DECLSPEC_HIDDEN;
321

322
extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
323
void release_typelib( void ) DECLSPEC_HIDDEN;
324

325
static inline void* __WINE_ALLOC_SIZE(1) heap_alloc( SIZE_T size )
326 327 328 329
{
    return HeapAlloc( GetProcessHeap(), 0, size );
}

330
static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero( SIZE_T size )
331 332 333 334
{
    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
}

335
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc( LPVOID mem, SIZE_T size )
336 337 338 339
{
    return HeapReAlloc( GetProcessHeap(), 0, mem, size );
}

340
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
341 342 343 344 345 346 347 348 349
{
    return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
}

static inline BOOL heap_free( LPVOID mem )
{
    return HeapFree( GetProcessHeap(), 0, mem );
}

350 351 352 353 354 355 356 357 358 359
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;
}

360 361 362 363 364 365 366 367 368 369 370 371
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;
}

372 373 374 375 376 377 378 379 380 381 382 383
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;
}

384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
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;
}

399 400
extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;

401
#endif /* _WINE_WINHTTP_PRIVATE_H_ */