winhttp_private.h 9.46 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/heap.h"
27
#include "wine/list.h"
28
#include "wine/unicode.h"
29

30
#include "ole2.h"
31
#include "sspi.h"
32
#include "wincrypt.h"
33

34 35
static const WCHAR getW[]    = {'G','E','T',0};
static const WCHAR postW[]   = {'P','O','S','T',0};
36
static const WCHAR headW[]   = {'H','E','A','D',0};
37
static const WCHAR slashW[]  = {'/',0};
38
static const WCHAR http1_0[] = {'H','T','T','P','/','1','.','0',0};
39
static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
40
static const WCHAR chunkedW[] = {'c','h','u','n','k','e','d',0};
41

42 43
struct object_header;
struct object_vtbl
44
{
45 46 47 48
    void (*destroy)( struct object_header * );
    BOOL (*query_option)( struct object_header *, DWORD, void *, DWORD * );
    BOOL (*set_option)( struct object_header *, DWORD, void *, DWORD );
};
49

50
struct object_header
51 52 53
{
    DWORD type;
    HINTERNET handle;
54
    const struct object_vtbl *vtbl;
55
    DWORD flags;
56 57 58
    DWORD disable_flags;
    DWORD logon_policy;
    DWORD redirect_policy;
59 60 61 62 63 64 65 66 67
    DWORD error;
    DWORD_PTR context;
    LONG refs;
    WINHTTP_STATUS_CALLBACK callback;
    DWORD notify_mask;
    struct list entry;
    struct list children;
};

68 69
struct hostdata
{
70 71 72 73 74
    struct list entry;
    LONG ref;
    WCHAR *hostname;
    INTERNET_PORT port;
    BOOL secure;
75
    struct list connections;
76
};
77

78
struct session
79
{
80
    struct object_header hdr;
81
    CRITICAL_SECTION cs;
82
    WCHAR *agent;
83
    DWORD access;
84
    int resolve_timeout;
85 86
    int connect_timeout;
    int send_timeout;
87 88
    int receive_timeout;
    int receive_response_timeout;
89 90 91 92
    WCHAR *proxy_server;
    WCHAR *proxy_bypass;
    WCHAR *proxy_username;
    WCHAR *proxy_password;
93
    struct list cookie_cache;
94
    HANDLE unload_event;
95
    DWORD secure_protocols;
96
};
97

98
struct connect
99
{
100
    struct object_header hdr;
101
    struct session *session;
102 103 104 105
    WCHAR *hostname;    /* final destination of the request */
    WCHAR *servername;  /* name of the server we directly connect to */
    WCHAR *username;
    WCHAR *password;
106 107
    INTERNET_PORT hostport;
    INTERNET_PORT serverport;
108
    struct sockaddr_storage sockaddr;
109
    BOOL resolved;
110
};
111

112
struct netconn
113
{
114
    struct list entry;
115
    int socket;
116
    struct sockaddr_storage sockaddr;
117
    BOOL secure; /* SSL active on connection? */
118
    struct hostdata *host;
119
    ULONGLONG keep_until;
120 121
    CtxtHandle ssl_ctx;
    SecPkgContext_StreamSizes ssl_sizes;
122
    char *ssl_buf;
123 124
    char *extra_buf;
    size_t extra_len;
125 126 127
    char *peek_msg;
    char *peek_msg_mem;
    size_t peek_len;
128
};
129

130
struct header
131
{
132 133
    WCHAR *field;
    WCHAR *value;
134
    BOOL is_request; /* part of request headers? */
135
};
136

137 138 139 140 141 142 143 144
enum auth_target
{
    TARGET_INVALID = -1,
    TARGET_SERVER,
    TARGET_PROXY,
    TARGET_MAX
};

145 146 147 148 149 150 151
enum auth_scheme
{
    SCHEME_INVALID = -1,
    SCHEME_BASIC,
    SCHEME_NTLM,
    SCHEME_PASSPORT,
    SCHEME_DIGEST,
152 153
    SCHEME_NEGOTIATE,
    SCHEME_MAX
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
};

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

169
struct request
170
{
171
    struct object_header hdr;
172
    struct connect *connect;
173 174 175 176
    WCHAR *verb;
    WCHAR *path;
    WCHAR *version;
    WCHAR *raw_headers;
177 178
    void *optional;
    DWORD optional_len;
179
    struct netconn *netconn;
180
    DWORD security_flags;
181
    BOOL check_revocation;
182
    const CERT_CONTEXT *server_cert;
183 184 185
    const CERT_CONTEXT *client_cert;
    CredHandle cred_handle;
    BOOL cred_handle_initialized;
186
    int resolve_timeout;
187
    int connect_timeout;
188
    int send_timeout;
189 190
    int receive_timeout;
    int receive_response_timeout;
191
    WCHAR *status_text;
192
    DWORD content_length; /* total number of bytes to be read */
193
    DWORD content_read;   /* bytes read so far */
194
    BOOL  read_chunked;   /* are we reading in chunked mode? */
195 196
    BOOL  read_chunked_eof;  /* end of stream in chunked mode */
    BOOL  read_chunked_size; /* chunk size remaining */
197 198
    DWORD read_pos;       /* current read position in read_buf */
    DWORD read_size;      /* valid data size in read_buf */
199
    char  read_buf[8192]; /* buffer for already read but not returned data */
200
    struct header *headers;
201
    DWORD num_headers;
202 203
    struct authinfo *authinfo;
    struct authinfo *proxy_authinfo;
204 205
    HANDLE task_wait;
    HANDLE task_cancel;
206
    BOOL   task_proc_running;
207 208
    struct list task_queue;
    CRITICAL_SECTION task_cs;
209 210 211 212 213
    struct
    {
        WCHAR *username;
        WCHAR *password;
    } creds[TARGET_MAX][SCHEME_MAX];
214
};
215

216
struct task_header
217
{
218
    struct list entry;
219
    struct request *request;
220
    void (*proc)( struct task_header * );
221 222
};

223
struct send_request
224
{
225
    struct task_header hdr;
226
    WCHAR *headers;
227
    DWORD headers_len;
228
    void *optional;
229 230 231
    DWORD optional_len;
    DWORD total_len;
    DWORD_PTR context;
232
};
233

234
struct receive_response
235
{
236
    struct task_header hdr;
237
};
238

239
struct query_data
240
{
241
    struct task_header hdr;
242 243
    DWORD *available;
};
244

245
struct read_data
246
{
247
    struct task_header hdr;
248
    void *buffer;
249
    DWORD to_read;
250 251
    DWORD *read;
};
252

253
struct write_data
254
{
255
    struct task_header hdr;
256
    const void *buffer;
257
    DWORD to_write;
258 259
    DWORD *written;
};
260

261 262 263 264
struct object_header *addref_object( struct object_header * ) DECLSPEC_HIDDEN;
struct object_header *grab_object( HINTERNET ) DECLSPEC_HIDDEN;
void release_object( struct object_header * ) DECLSPEC_HIDDEN;
HINTERNET alloc_handle( struct object_header * ) DECLSPEC_HIDDEN;
265
BOOL free_handle( HINTERNET ) DECLSPEC_HIDDEN;
266

267
void send_callback( struct object_header *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN;
268
void close_connection( struct request * ) DECLSPEC_HIDDEN;
269

270 271
void netconn_close( struct netconn * ) DECLSPEC_HIDDEN;
struct netconn *netconn_create( struct hostdata *, const struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
272
void netconn_unload( void ) DECLSPEC_HIDDEN;
273 274
ULONG netconn_query_data_available( struct netconn * ) DECLSPEC_HIDDEN;
BOOL netconn_recv( struct netconn *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
275
BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_storage *, int ) DECLSPEC_HIDDEN;
276 277 278 279 280 281
BOOL netconn_secure_connect( struct netconn *, WCHAR *, DWORD, CredHandle *, BOOL ) DECLSPEC_HIDDEN;
BOOL netconn_send( struct netconn *, const void *, size_t, int * ) DECLSPEC_HIDDEN;
DWORD netconn_set_timeout( struct netconn *, BOOL, int ) DECLSPEC_HIDDEN;
BOOL netconn_is_alive( struct netconn * ) DECLSPEC_HIDDEN;
const void *netconn_get_certificate( struct netconn * ) DECLSPEC_HIDDEN;
int netconn_get_cipher_strength( struct netconn * ) DECLSPEC_HIDDEN;
282

283 284 285
BOOL set_cookies( struct request *, const WCHAR * ) DECLSPEC_HIDDEN;
BOOL add_cookie_headers( struct request * ) DECLSPEC_HIDDEN;
BOOL add_request_headers( struct request *, const WCHAR *, DWORD, DWORD ) DECLSPEC_HIDDEN;
286
void destroy_cookies( struct session * ) DECLSPEC_HIDDEN;
287
BOOL set_server_for_hostname( struct connect *, const WCHAR *, INTERNET_PORT ) DECLSPEC_HIDDEN;
288
void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN;
289

290 291
void release_host( struct hostdata * ) DECLSPEC_HIDDEN;
BOOL process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOOL ) DECLSPEC_HIDDEN;
292

293
extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
294
void release_typelib( void ) DECLSPEC_HIDDEN;
295

296
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
297 298 299 300
{
    return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
}

301 302 303 304 305 306 307 308 309 310
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;
}

311 312 313 314 315 316 317 318 319 320 321 322
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;
}

323 324 325 326 327 328 329 330 331 332 333 334
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;
}

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
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;
}

350 351
extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;

352
#endif /* _WINE_WINHTTP_PRIVATE_H_ */