winhttp_private.h 9.04 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
#include "ole2.h"
46

47 48
static const WCHAR getW[]    = {'G','E','T',0};
static const WCHAR postW[]   = {'P','O','S','T',0};
49
static const WCHAR headW[]   = {'H','E','A','D',0};
50
static const WCHAR slashW[]  = {'/',0};
51
static const WCHAR http1_0[] = {'H','T','T','P','/','1','.','0',0};
52 53
static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};

54 55 56 57 58
typedef struct _object_header_t object_header_t;

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

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
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;

96 97 98 99 100
typedef struct
{
    object_header_t hdr;
    LPWSTR agent;
    DWORD access;
101
    int resolve_timeout;
102 103 104
    int connect_timeout;
    int send_timeout;
    int recv_timeout;
105 106 107 108
    LPWSTR proxy_server;
    LPWSTR proxy_bypass;
    LPWSTR proxy_username;
    LPWSTR proxy_password;
109
    struct list cookie_cache;
110 111
} session_t;

112 113 114 115 116 117 118 119 120 121
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;
122
    struct sockaddr_storage sockaddr;
123
    BOOL resolved;
124 125
} connect_t;

126 127 128
typedef struct
{
    int socket;
129 130
    BOOL secure; /* SSL active on connection? */
    void *ssl_conn;
131 132 133
    char *peek_msg;
    char *peek_msg_mem;
    size_t peek_len;
134
    DWORD security_flags;
135 136 137 138 139 140
} netconn_t;

typedef struct
{
    LPWSTR field;
    LPWSTR value;
141
    BOOL is_request; /* part of request headers? */
142 143 144 145 146 147 148 149 150 151 152
} header_t;

typedef struct
{
    object_header_t hdr;
    connect_t *connect;
    LPWSTR verb;
    LPWSTR path;
    LPWSTR version;
    LPWSTR raw_headers;
    netconn_t netconn;
153
    int resolve_timeout;
154
    int connect_timeout;
155 156
    int send_timeout;
    int recv_timeout;
157 158 159 160 161
    LPWSTR status_text;
    DWORD content_length; /* total number of bytes to be read (per chunk) */
    DWORD content_read;   /* bytes read so far */
    header_t *headers;
    DWORD num_headers;
162 163
    WCHAR **accept_types;
    DWORD num_accept_types;
164 165
} request_t;

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
typedef struct _task_header_t task_header_t;

struct _task_header_t
{
    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;

212 213 214 215 216
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;
217

218 219 220 221
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;
222

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
BOOL netconn_close( netconn_t * ) DECLSPEC_HIDDEN;
BOOL netconn_connect( netconn_t *, const struct sockaddr *, unsigned int, int ) DECLSPEC_HIDDEN;
BOOL netconn_connected( netconn_t * ) DECLSPEC_HIDDEN;
BOOL netconn_create( netconn_t *, int, int, int ) DECLSPEC_HIDDEN;
BOOL netconn_get_next_line( netconn_t *, char *, DWORD * ) DECLSPEC_HIDDEN;
BOOL netconn_init( netconn_t *, BOOL ) DECLSPEC_HIDDEN;
void netconn_unload( void ) DECLSPEC_HIDDEN;
BOOL netconn_query_data_available( netconn_t *, DWORD * ) DECLSPEC_HIDDEN;
BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;
BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr *, socklen_t *, int ) DECLSPEC_HIDDEN;
BOOL netconn_secure_connect( netconn_t *, WCHAR * ) DECLSPEC_HIDDEN;
BOOL netconn_send( netconn_t *, const void *, size_t, int, int * ) DECLSPEC_HIDDEN;
DWORD netconn_set_timeout( netconn_t *, BOOL, int ) DECLSPEC_HIDDEN;
const void *netconn_get_certificate( netconn_t * ) DECLSPEC_HIDDEN;
int netconn_get_cipher_strength( netconn_t * ) DECLSPEC_HIDDEN;
238

239 240 241 242 243
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;
BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port ) DECLSPEC_HIDDEN;
244

245 246
extern HRESULT WinHttpRequest_create( IUnknown *, void ** ) DECLSPEC_HIDDEN;

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
static inline const char *debugstr_variant( const VARIANT *v )
{
    if (!v) return "(null)";
    switch (V_VT(v))
    {
    case VT_EMPTY:
        return "{VT_EMPTY}";
    case VT_NULL:
        return "{VT_NULL}";
    case VT_I4:
        return wine_dbg_sprintf( "{VT_I4: %d}", V_I4(v) );
    case VT_R8:
        return wine_dbg_sprintf( "{VT_R8: %lf}", V_R8(v) );
    case VT_BSTR:
        return wine_dbg_sprintf( "{VT_BSTR: %s}", debugstr_w(V_BSTR(v)) );
    case VT_DISPATCH:
        return wine_dbg_sprintf( "{VT_DISPATCH: %p}", V_DISPATCH(v) );
    case VT_BOOL:
        return wine_dbg_sprintf( "{VT_BOOL: %x}", V_BOOL(v) );
    case VT_UNKNOWN:
        return wine_dbg_sprintf( "{VT_UNKNOWN: %p}", V_UNKNOWN(v) );
    case VT_UINT:
        return wine_dbg_sprintf( "{VT_UINT: %u}", V_UINT(v) );
    case VT_BSTR|VT_BYREF:
        return wine_dbg_sprintf( "{VT_BSTR|VT_BYREF: ptr %p, data %s}",
            V_BSTRREF(v), V_BSTRREF(v) ? debugstr_w( *V_BSTRREF(v) ) : NULL );
    default:
        return wine_dbg_sprintf( "{vt %d}", V_VT(v) );
    }
}

278 279 280 281 282 283 284 285 286 287
static inline void *heap_alloc( SIZE_T size )
{
    return HeapAlloc( GetProcessHeap(), 0, size );
}

static inline void *heap_alloc_zero( SIZE_T size )
{
    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
}

288 289 290 291 292
static inline void *heap_realloc( LPVOID mem, SIZE_T size )
{
    return HeapReAlloc( GetProcessHeap(), 0, mem, size );
}

293 294 295 296 297 298 299 300 301 302
static inline void *heap_realloc_zero( LPVOID mem, SIZE_T size )
{
    return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
}

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

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

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

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

337
#endif /* _WINE_WINHTTP_PRIVATE_H_ */