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 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
30 #include "wine/unicode.h"
31 #include "wine/list.h"
37 #ifdef HAVE_NETINET_IN_H
38 # include <sys/types.h>
39 # include <netinet/in.h>
41 #ifdef HAVE_SYS_SOCKET_H
42 # include <sys/socket.h>
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
52 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
54 #ifndef INET6_ADDRSTRLEN
55 #define INET6_ADDRSTRLEN 46
62 struct sockaddr_storage addr;
64 char addr_str[INET6_ADDRSTRLEN];
66 WCHAR *scheme_host_port;
67 const WCHAR *host_port;
68 const WCHAR *canon_host_port;
73 const CERT_CHAIN_CONTEXT *cert_chain;
76 struct list conn_pool;
79 void server_addref(server_t*) DECLSPEC_HIDDEN;
80 void server_release(server_t*) DECLSPEC_HIDDEN;
87 BOOL collect_connections(collect_type_t) DECLSPEC_HIDDEN;
89 /* used for netconnection.c stuff */
101 struct list pool_entry;
104 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
106 return HeapAlloc(GetProcessHeap(), 0, len);
109 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
111 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
114 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
116 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
119 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
121 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
124 static inline BOOL heap_free(void *mem)
126 return HeapFree(GetProcessHeap(), 0, mem);
129 static inline LPWSTR heap_strdupW(LPCWSTR str)
136 size = (strlenW(str)+1)*sizeof(WCHAR);
137 ret = heap_alloc(size);
139 memcpy(ret, str, size);
145 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
153 for(len=0; len<max_len; len++)
157 ret = heap_alloc(sizeof(WCHAR)*(len+1));
159 memcpy(ret, str, sizeof(WCHAR)*len);
166 static inline WCHAR *heap_strdupAtoW(const char *str)
173 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
174 ret = heap_alloc(len*sizeof(WCHAR));
176 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
182 static inline char *heap_strdupWtoA(LPCWSTR str)
187 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
188 ret = heap_alloc(size);
190 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
196 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
198 dataA->dwFileAttributes = dataW->dwFileAttributes;
199 dataA->ftCreationTime = dataW->ftCreationTime;
200 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
201 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
202 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
203 dataA->nFileSizeLow = dataW->nFileSizeLow;
204 dataA->dwReserved0 = dataW->dwReserved0;
205 dataA->dwReserved1 = dataW->dwReserved1;
206 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
207 dataA->cFileName, sizeof(dataA->cFileName),
209 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
210 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
216 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
217 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
218 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
219 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
220 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
221 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
222 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
225 #define INET_OPENURL 0x0001
226 #define INET_CALLBACKW 0x0002
228 typedef struct _object_header_t object_header_t;
231 void (*Destroy)(object_header_t*);
232 void (*CloseConnection)(object_header_t*);
233 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
234 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
235 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
236 DWORD (*ReadFileEx)(object_header_t*,void*,DWORD,DWORD*,DWORD,DWORD_PTR);
237 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
238 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
239 DWORD (*FindNextFileW)(object_header_t*,void*);
242 #define INTERNET_HANDLE_IN_USE 1
244 struct _object_header_t
247 const object_vtbl_t *vtbl;
254 DWORD dwInternalFlags;
256 INTERNET_STATUS_CALLBACK lpfnStatusCB;
258 struct list children;
268 LPWSTR proxyUsername;
269 LPWSTR proxyPassword;
271 DWORD connect_timeout;
278 LPWSTR hostName; /* the final destination of the request */
281 INTERNET_PORT hostPort; /* the final destination port of the request */
282 DWORD connect_timeout;
284 DWORD receive_timeout;
287 #define HDR_ISREQUEST 0x0001
288 #define HDR_COMMADELIMITED 0x0002
289 #define HDR_SEMIDELIMITED 0x0004
297 } HTTPHEADERW, *LPHTTPHEADERW;
302 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
305 const data_stream_vtbl_t *vtbl;
309 data_stream_t data_stream;
310 DWORD content_length;
314 #define READ_BUFFER_SIZE 8192
319 http_session_t *session;
326 DWORD security_flags;
327 DWORD connect_timeout;
329 DWORD receive_timeout;
335 HTTPHEADERW *custHeaders;
337 FILETIME last_modified;
341 struct HttpAuthInfo *authInfo;
342 struct HttpAuthInfo *proxyAuthInfo;
344 CRITICAL_SECTION read_section; /* section to protect the following fields */
345 DWORD contentLength; /* total number of bytes to be read */
346 BOOL read_chunked; /* are we reading in chunked mode? */
347 BOOL read_gzip; /* are we reading in gzip mode? */
348 DWORD read_pos; /* current read position in read_buf */
349 DWORD read_size; /* valid data size in read_buf */
350 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
353 data_stream_t *data_stream;
354 netconn_stream_t netconn_stream;
357 typedef struct task_header_t task_header_t;
358 typedef void (*async_task_proc_t)(task_header_t*);
362 async_task_proc_t proc;
363 object_header_t *hdr;
366 void *alloc_async_task(object_header_t*,async_task_proc_t,size_t) DECLSPEC_HIDDEN;
368 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
369 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
370 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
371 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
373 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
374 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
376 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
378 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
379 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
380 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
381 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
383 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
384 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
385 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
386 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
388 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
389 struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
391 DWORD get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
392 BOOL set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
394 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
395 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
396 DWORD INTERNET_AsyncCall(task_header_t*) DECLSPEC_HIDDEN;
397 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
398 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen) DECLSPEC_HIDDEN;
400 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
401 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
402 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
404 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
405 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
406 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
407 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
409 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
410 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
411 void NETCON_unload(void) DECLSPEC_HIDDEN;
412 DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN;
413 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
414 int *sent /* out */) DECLSPEC_HIDDEN;
415 DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, int flags,
416 int *recvd /* out */) DECLSPEC_HIDDEN;
417 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
418 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
419 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
420 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
421 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
422 int sock_get_error(int) DECLSPEC_HIDDEN;
424 server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL);
426 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
427 void free_urlcache(void) DECLSPEC_HIDDEN;
428 void free_cookie(void) DECLSPEC_HIDDEN;
430 #define MAX_REPLY_LEN 0x5B4
432 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
439 /* Undocumented security flags */
440 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
441 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
442 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
443 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
445 #define _SECURITY_ERROR_FLAGS_MASK \
446 (_SECURITY_FLAG_CERT_REV_FAILED \
447 |_SECURITY_FLAG_CERT_INVALID_CA \
448 |_SECURITY_FLAG_CERT_INVALID_CN \
449 |_SECURITY_FLAG_CERT_INVALID_DATE)
451 #endif /* _WINE_INTERNET_H_ */