4 * Copyright 1999 Corel Corporation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
26 #include "wine/heap.h"
27 #include "wine/list.h"
33 extern HMODULE WININET_hModule DECLSPEC_HIDDEN
;
39 struct sockaddr_storage addr
;
41 char addr_str
[INET6_ADDRSTRLEN
];
43 WCHAR
*scheme_host_port
;
44 const WCHAR
*host_port
;
45 const WCHAR
*canon_host_port
;
50 const CERT_CHAIN_CONTEXT
*cert_chain
;
53 struct list conn_pool
;
56 void server_addref(server_t
*) DECLSPEC_HIDDEN
;
57 void server_release(server_t
*) DECLSPEC_HIDDEN
;
64 BOOL
collect_connections(collect_type_t
) DECLSPEC_HIDDEN
;
66 /* used for netconnection.c stuff */
73 SecPkgContext_StreamSizes ssl_sizes
;
86 struct list pool_entry
;
89 BOOL
is_valid_netconn(netconn_t
*) DECLSPEC_HIDDEN
;
90 void close_netconn(netconn_t
*) DECLSPEC_HIDDEN
;
92 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem
, size_t len
)
94 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
97 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
104 size
= (lstrlenW(str
)+1)*sizeof(WCHAR
);
105 ret
= heap_alloc(size
);
107 memcpy(ret
, str
, size
);
113 static inline char *heap_strdupA(const char *str
)
118 DWORD size
= strlen(str
)+1;
120 ret
= heap_alloc(size
);
122 memcpy(ret
, str
, size
);
128 static inline LPWSTR
heap_strndupW(LPCWSTR str
, UINT max_len
)
136 for(len
=0; len
<max_len
; len
++)
140 ret
= heap_alloc(sizeof(WCHAR
)*(len
+1));
142 memcpy(ret
, str
, sizeof(WCHAR
)*len
);
149 static inline WCHAR
*heap_strndupAtoW(const char *str
, int len_a
, DWORD
*len_w
)
158 len_a
= strnlen(str
, len_a
);
159 len
= MultiByteToWideChar(CP_ACP
, 0, str
, len_a
, NULL
, 0);
160 ret
= heap_alloc((len
+1)*sizeof(WCHAR
));
162 MultiByteToWideChar(CP_ACP
, 0, str
, len_a
, ret
, len
);
171 static inline WCHAR
*heap_strdupAtoW(const char *str
)
178 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
179 ret
= heap_alloc(len
*sizeof(WCHAR
));
181 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
187 static inline char *heap_strdupWtoA(LPCWSTR str
)
192 DWORD size
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
193 ret
= heap_alloc(size
);
195 WideCharToMultiByte(CP_ACP
, 0, str
, -1, ret
, size
, NULL
, NULL
);
206 static inline substr_t
substr(const WCHAR
*str
, size_t len
)
208 substr_t r
= {str
, len
};
212 static inline substr_t
substrz(const WCHAR
*str
)
214 return substr(str
, lstrlenW(str
));
217 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW
, LPWIN32_FIND_DATAA dataA
)
219 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
220 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
221 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
222 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
223 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
224 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
225 dataA
->dwReserved0
= dataW
->dwReserved0
;
226 dataA
->dwReserved1
= dataW
->dwReserved1
;
227 WideCharToMultiByte(CP_ACP
, 0, dataW
->cFileName
, -1,
228 dataA
->cFileName
, sizeof(dataA
->cFileName
),
230 WideCharToMultiByte(CP_ACP
, 0, dataW
->cAlternateFileName
, -1,
231 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
),
237 WH_HINIT
= INTERNET_HANDLE_TYPE_INTERNET
,
238 WH_HFTPSESSION
= INTERNET_HANDLE_TYPE_CONNECT_FTP
,
239 WH_HGOPHERSESSION
= INTERNET_HANDLE_TYPE_CONNECT_GOPHER
,
240 WH_HHTTPSESSION
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
,
241 WH_HFILE
= INTERNET_HANDLE_TYPE_FTP_FILE
,
242 WH_HFTPFINDNEXT
= INTERNET_HANDLE_TYPE_FTP_FIND
,
243 WH_HHTTPREQ
= INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
246 #define INET_OPENURL 0x0001
247 #define INET_CALLBACKW 0x0002
258 typedef struct _object_header_t object_header_t
;
261 void (*Destroy
)(object_header_t
*);
262 void (*CloseConnection
)(object_header_t
*);
263 DWORD (*QueryOption
)(object_header_t
*,DWORD
,void*,DWORD
*,BOOL
);
264 DWORD (*SetOption
)(object_header_t
*,DWORD
,void*,DWORD
);
265 DWORD (*ReadFile
)(object_header_t
*,void*,DWORD
,DWORD
*,DWORD
,DWORD_PTR
);
266 DWORD (*WriteFile
)(object_header_t
*,const void*,DWORD
,DWORD
*);
267 DWORD (*QueryDataAvailable
)(object_header_t
*,DWORD
*,DWORD
,DWORD_PTR
);
268 DWORD (*FindNextFileW
)(object_header_t
*,void*);
269 DWORD (*LockRequestFile
)(object_header_t
*,req_file_t
**);
272 #define INTERNET_HANDLE_IN_USE 1
274 struct _object_header_t
277 const object_vtbl_t
*vtbl
;
284 DWORD dwInternalFlags
;
287 INTERNET_STATUS_CALLBACK lpfnStatusCB
;
289 struct list children
;
298 LPWSTR proxyUsername
;
299 LPWSTR proxyPassword
;
301 DWORD connect_timeout
;
308 LPWSTR hostName
; /* the final destination of the request */
311 INTERNET_PORT hostPort
; /* the final destination port of the request */
312 DWORD connect_timeout
;
314 DWORD receive_timeout
;
317 #define HDR_ISREQUEST 0x0001
318 #define HDR_COMMADELIMITED 0x0002
319 #define HDR_SEMIDELIMITED 0x0004
327 } HTTPHEADERW
, *LPHTTPHEADERW
;
332 typedef struct data_stream_vtbl_t data_stream_vtbl_t
;
335 const data_stream_vtbl_t
*vtbl
;
339 data_stream_t data_stream
;
340 ULONGLONG content_length
;
341 ULONGLONG content_read
;
344 #define READ_BUFFER_SIZE 8192
349 http_session_t
*session
;
355 DWORD security_flags
;
356 DWORD connect_timeout
;
358 DWORD receive_timeout
;
364 BOOL clear_auth
; /* Flag to clear the password field on the authorization dialog */
366 CRITICAL_SECTION headers_section
; /* section to protect the headers array */
367 HTTPHEADERW
*custHeaders
;
370 FILETIME last_modified
;
372 req_file_t
*req_file
;
374 struct HttpAuthInfo
*authInfo
;
375 struct HttpAuthInfo
*proxyAuthInfo
;
377 CRITICAL_SECTION read_section
; /* section to protect the following fields */
378 ULONGLONG contentLength
; /* total number of bytes to be read */
379 BOOL read_gzip
; /* are we reading in gzip mode? */
380 DWORD read_pos
; /* current read position in read_buf */
381 DWORD read_size
; /* valid data size in read_buf */
382 BYTE read_buf
[READ_BUFFER_SIZE
]; /* buffer for already read but not returned data */
384 data_stream_t
*data_stream
;
385 netconn_stream_t netconn_stream
;
388 typedef struct task_header_t task_header_t
;
389 typedef void (*async_task_proc_t
)(task_header_t
*);
393 async_task_proc_t proc
;
394 object_header_t
*hdr
;
397 void *alloc_async_task(object_header_t
*,async_task_proc_t
,size_t) DECLSPEC_HIDDEN
;
399 void *alloc_object(object_header_t
*,const object_vtbl_t
*,size_t) DECLSPEC_HIDDEN
;
400 object_header_t
*get_handle_object( HINTERNET hinternet
) DECLSPEC_HIDDEN
;
401 object_header_t
*WININET_AddRef( object_header_t
*info
) DECLSPEC_HIDDEN
;
402 BOOL
WININET_Release( object_header_t
*info
) DECLSPEC_HIDDEN
;
404 DWORD
INET_QueryOption(object_header_t
*,DWORD
,void*,DWORD
*,BOOL
) DECLSPEC_HIDDEN
;
405 DWORD
INET_SetOption(object_header_t
*,DWORD
,void*,DWORD
) DECLSPEC_HIDDEN
;
407 time_t ConvertTimeString(LPCWSTR asctime
) DECLSPEC_HIDDEN
;
409 HINTERNET
FTP_Connect(appinfo_t
*hIC
, LPCWSTR lpszServerName
,
410 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
411 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
412 DWORD dwInternalFlags
) DECLSPEC_HIDDEN
;
414 DWORD
HTTP_Connect(appinfo_t
*,LPCWSTR
,
415 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
416 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
417 DWORD dwInternalFlags
, HINTERNET
*) DECLSPEC_HIDDEN
;
419 BOOL
GetAddress(const WCHAR
*,INTERNET_PORT
,SOCKADDR
*,int*,char*) DECLSPEC_HIDDEN
;
421 DWORD
get_cookie_header(const WCHAR
*,const WCHAR
*,WCHAR
**) DECLSPEC_HIDDEN
;
422 DWORD
set_cookie(substr_t
,substr_t
,substr_t
,substr_t
,DWORD
) DECLSPEC_HIDDEN
;
424 void INTERNET_SetLastError(DWORD dwError
) DECLSPEC_HIDDEN
;
425 DWORD
INTERNET_GetLastError(void) DECLSPEC_HIDDEN
;
426 DWORD
INTERNET_AsyncCall(task_header_t
*) DECLSPEC_HIDDEN
;
427 LPSTR
INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN
;
429 VOID
INTERNET_SendCallback(object_header_t
*hdr
, DWORD_PTR dwContext
,
430 DWORD dwInternetStatus
, LPVOID lpvStatusInfo
,
431 DWORD dwStatusInfoLength
) DECLSPEC_HIDDEN
;
432 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
) DECLSPEC_HIDDEN
;
434 DWORD
create_netconn(server_t
*,DWORD
,BOOL
,DWORD
,netconn_t
**) DECLSPEC_HIDDEN
;
435 void free_netconn(netconn_t
*) DECLSPEC_HIDDEN
;
436 void NETCON_unload(void) DECLSPEC_HIDDEN
;
437 DWORD
NETCON_secure_connect(netconn_t
*,server_t
*) DECLSPEC_HIDDEN
;
438 DWORD
NETCON_send(netconn_t
*connection
, const void *msg
, size_t len
, int flags
,
439 int *sent
/* out */) DECLSPEC_HIDDEN
;
440 DWORD
NETCON_recv(netconn_t
*,void*,size_t,BOOL
,int*) DECLSPEC_HIDDEN
;
441 BOOL
NETCON_is_alive(netconn_t
*) DECLSPEC_HIDDEN
;
442 LPCVOID
NETCON_GetCert(netconn_t
*connection
) DECLSPEC_HIDDEN
;
443 int NETCON_GetCipherStrength(netconn_t
*) DECLSPEC_HIDDEN
;
444 DWORD
NETCON_set_timeout(netconn_t
*connection
, BOOL send
, DWORD value
) DECLSPEC_HIDDEN
;
445 int sock_send(int fd
, const void *msg
, size_t len
, int flags
) DECLSPEC_HIDDEN
;
446 int sock_recv(int fd
, void *msg
, size_t len
, int flags
) DECLSPEC_HIDDEN
;
448 server_t
*get_server(substr_t
,INTERNET_PORT
,BOOL
,BOOL
) DECLSPEC_HIDDEN
;
450 DWORD
create_req_file(const WCHAR
*,req_file_t
**) DECLSPEC_HIDDEN
;
451 void req_file_release(req_file_t
*) DECLSPEC_HIDDEN
;
453 static inline req_file_t
*req_file_addref(req_file_t
*req_file
)
455 InterlockedIncrement(&req_file
->ref
);
459 BOOL
init_urlcache(void) DECLSPEC_HIDDEN
;
460 void free_urlcache(void) DECLSPEC_HIDDEN
;
461 void free_cookie(void) DECLSPEC_HIDDEN
;
462 void free_authorization_cache(void) DECLSPEC_HIDDEN
;
464 void init_winsock(void) DECLSPEC_HIDDEN
;
466 #define MAX_REPLY_LEN 0x1000
468 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
475 /* Undocumented security flags */
476 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
477 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
478 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
479 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
481 #define _SECURITY_ERROR_FLAGS_MASK \
482 (_SECURITY_FLAG_CERT_REV_FAILED \
483 |_SECURITY_FLAG_CERT_INVALID_CA \
484 |_SECURITY_FLAG_CERT_INVALID_CN \
485 |_SECURITY_FLAG_CERT_INVALID_DATE)
487 #endif /* _WINE_INTERNET_H_ */