comctl32/tests: Destroy the window after the tests.
[wine] / dlls / winhttp / winhttp_private.h
1 /*
2  * Copyright 2008 Hans Leidekker for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifndef _WINE_WINHTTP_PRIVATE_H_
20 #define _WINE_WINHTTP_PRIVATE_H_
21
22 #ifndef __WINE_CONFIG_H
23 # error You must include config.h to use this header
24 #endif
25
26 #include "wine/list.h"
27 #include "wine/unicode.h"
28
29 #ifdef HAVE_NETINET_IN_H
30 # include <netinet/in.h>
31 #endif
32 #ifdef HAVE_NETDB_H
33 # include <netdb.h>
34 #endif
35 #if defined(__MINGW32__) || defined (_MSC_VER)
36 # include <ws2tcpip.h>
37 #else
38 # define closesocket close
39 # define ioctlsocket ioctl
40 #endif
41
42 static const WCHAR getW[]    = {'G','E','T',0};
43 static const WCHAR postW[]   = {'P','O','S','T',0};
44 static const WCHAR slashW[]  = {'/',0};
45 static const WCHAR http1_0[] = {'H','T','T','P','/','1','.','0',0};
46 static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
47
48 typedef struct _object_header_t object_header_t;
49
50 typedef struct
51 {
52     void (*destroy)( object_header_t * );
53     BOOL (*query_option)( object_header_t *, DWORD, void *, DWORD * );
54     BOOL (*set_option)( object_header_t *, DWORD, void *, DWORD );
55 } object_vtbl_t;
56
57 struct _object_header_t
58 {
59     DWORD type;
60     HINTERNET handle;
61     const object_vtbl_t *vtbl;
62     DWORD flags;
63     DWORD disable_flags;
64     DWORD logon_policy;
65     DWORD redirect_policy;
66     DWORD error;
67     DWORD_PTR context;
68     LONG refs;
69     WINHTTP_STATUS_CALLBACK callback;
70     DWORD notify_mask;
71     struct list entry;
72     struct list children;
73 };
74
75 typedef struct
76 {
77     struct list entry;
78     WCHAR *name;
79     struct list cookies;
80 } domain_t;
81
82 typedef struct
83 {
84     struct list entry;
85     WCHAR *name;
86     WCHAR *value;
87     WCHAR *path;
88 } cookie_t;
89
90 typedef struct
91 {
92     object_header_t hdr;
93     LPWSTR agent;
94     DWORD access;
95     LPWSTR proxy_server;
96     LPWSTR proxy_bypass;
97     LPWSTR proxy_username;
98     LPWSTR proxy_password;
99     struct list cookie_cache;
100 } session_t;
101
102 typedef struct
103 {
104     object_header_t hdr;
105     session_t *session;
106     LPWSTR hostname;    /* final destination of the request */
107     LPWSTR servername;  /* name of the server we directly connect to */
108     LPWSTR username;
109     LPWSTR password;
110     INTERNET_PORT hostport;
111     INTERNET_PORT serverport;
112     struct sockaddr_in sockaddr;
113 } connect_t;
114
115 typedef struct
116 {
117     int socket;
118     BOOL secure; /* SSL active on connection? */
119     void *ssl_conn;
120     char *peek_msg;
121     char *peek_msg_mem;
122     size_t peek_len;
123 } netconn_t;
124
125 typedef struct
126 {
127     LPWSTR field;
128     LPWSTR value;
129     BOOL is_request; /* part of request headers? */
130 } header_t;
131
132 typedef struct
133 {
134     object_header_t hdr;
135     connect_t *connect;
136     LPWSTR verb;
137     LPWSTR path;
138     LPWSTR version;
139     LPWSTR raw_headers;
140     netconn_t netconn;
141     LPWSTR status_text;
142     DWORD content_length; /* total number of bytes to be read (per chunk) */
143     DWORD content_read;   /* bytes read so far */
144     header_t *headers;
145     DWORD num_headers;
146 } request_t;
147
148 typedef struct _task_header_t task_header_t;
149
150 struct _task_header_t
151 {
152     request_t *request;
153     void (*proc)( task_header_t * );
154 };
155
156 typedef struct
157 {
158     task_header_t hdr;
159     LPWSTR headers;
160     DWORD headers_len;
161     LPVOID optional;
162     DWORD optional_len;
163     DWORD total_len;
164     DWORD_PTR context;
165 } send_request_t;
166
167 typedef struct
168 {
169     task_header_t hdr;
170 } receive_response_t;
171
172 typedef struct
173 {
174     task_header_t hdr;
175     LPDWORD available;
176 } query_data_t;
177
178 typedef struct
179 {
180     task_header_t hdr;
181     LPVOID buffer;
182     DWORD to_read;
183     LPDWORD read;
184 } read_data_t;
185
186 typedef struct
187 {
188     task_header_t hdr;
189     LPCVOID buffer;
190     DWORD to_write;
191     LPDWORD written;
192 } write_data_t;
193
194 object_header_t *addref_object( object_header_t * );
195 object_header_t *grab_object( HINTERNET );
196 void release_object( object_header_t * );
197 HINTERNET alloc_handle( object_header_t * );
198 BOOL free_handle( HINTERNET );
199
200 void set_last_error( DWORD );
201 DWORD get_last_error( void );
202 void send_callback( object_header_t *, DWORD, LPVOID, DWORD );
203 void close_connection( request_t * );
204
205 BOOL netconn_close( netconn_t * );
206 BOOL netconn_connect( netconn_t *, const struct sockaddr *, unsigned int );
207 BOOL netconn_connected( netconn_t * );
208 BOOL netconn_create( netconn_t *, int, int, int );
209 BOOL netconn_get_next_line( netconn_t *, char *, DWORD * );
210 BOOL netconn_init( netconn_t *, BOOL );
211 BOOL netconn_query_data_available( netconn_t *, DWORD * );
212 BOOL netconn_recv( netconn_t *, void *, size_t, int, int * );
213 BOOL netconn_resolve( WCHAR *, INTERNET_PORT, struct sockaddr_in * );
214 BOOL netconn_secure_connect( netconn_t * );
215 BOOL netconn_send( netconn_t *, const void *, size_t, int, int * );
216 const void *netconn_get_certificate( netconn_t * );
217
218 BOOL set_cookies( request_t *, const WCHAR * );
219 BOOL add_cookie_headers( request_t * );
220 BOOL add_request_headers( request_t *, LPCWSTR, DWORD, DWORD );
221 void delete_domain( domain_t * );
222
223 static inline void *heap_alloc( SIZE_T size )
224 {
225     return HeapAlloc( GetProcessHeap(), 0, size );
226 }
227
228 static inline void *heap_alloc_zero( SIZE_T size )
229 {
230     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
231 }
232
233 static inline void *heap_realloc( LPVOID mem, SIZE_T size )
234 {
235     return HeapReAlloc( GetProcessHeap(), 0, mem, size );
236 }
237
238 static inline void *heap_realloc_zero( LPVOID mem, SIZE_T size )
239 {
240     return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
241 }
242
243 static inline BOOL heap_free( LPVOID mem )
244 {
245     return HeapFree( GetProcessHeap(), 0, mem );
246 }
247
248 static inline WCHAR *strdupW( const WCHAR *src )
249 {
250     WCHAR *dst;
251
252     if (!src) return NULL;
253     dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) );
254     if (dst) strcpyW( dst, src );
255     return dst;
256 }
257
258 static inline WCHAR *strdupAW( const char *src )
259 {
260     WCHAR *dst = NULL;
261     if (src)
262     {
263         DWORD len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
264         if ((dst = heap_alloc( len * sizeof(WCHAR) )))
265             MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
266     }
267     return dst;
268 }
269
270 static inline char *strdupWA( const WCHAR *src )
271 {
272     char *dst = NULL;
273     if (src)
274     {
275         int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
276         if ((dst = heap_alloc( len )))
277             WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
278     }
279     return dst;
280 }
281
282 #endif /* _WINE_WINHTTP_PRIVATE_H_ */