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
61 struct sockaddr_storage addr;
63 char addr_str[INET6_ADDRSTRLEN];
68 const CERT_CHAIN_CONTEXT *cert_chain;
71 struct list conn_pool;
74 void server_addref(server_t*) DECLSPEC_HIDDEN;
75 void server_release(server_t*) DECLSPEC_HIDDEN;
82 BOOL collect_connections(collect_type_t) DECLSPEC_HIDDEN;
84 /* used for netconnection.c stuff */
96 struct list pool_entry;
99 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
101 return HeapAlloc(GetProcessHeap(), 0, len);
104 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
106 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
109 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
111 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
114 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
116 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
119 static inline BOOL heap_free(void *mem)
121 return HeapFree(GetProcessHeap(), 0, mem);
124 static inline LPWSTR heap_strdupW(LPCWSTR str)
131 size = (strlenW(str)+1)*sizeof(WCHAR);
132 ret = heap_alloc(size);
134 memcpy(ret, str, size);
140 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
148 for(len=0; len<max_len; len++)
152 ret = heap_alloc(sizeof(WCHAR)*(len+1));
154 memcpy(ret, str, sizeof(WCHAR)*len);
161 static inline WCHAR *heap_strdupAtoW(const char *str)
168 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
169 ret = heap_alloc(len*sizeof(WCHAR));
171 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
177 static inline char *heap_strdupWtoA(LPCWSTR str)
182 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
183 ret = heap_alloc(size);
185 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
191 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
193 dataA->dwFileAttributes = dataW->dwFileAttributes;
194 dataA->ftCreationTime = dataW->ftCreationTime;
195 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
196 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
197 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
198 dataA->nFileSizeLow = dataW->nFileSizeLow;
199 dataA->dwReserved0 = dataW->dwReserved0;
200 dataA->dwReserved1 = dataW->dwReserved1;
201 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
202 dataA->cFileName, sizeof(dataA->cFileName),
204 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
205 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
211 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
212 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
213 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
214 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
215 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
216 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
217 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
220 #define INET_OPENURL 0x0001
221 #define INET_CALLBACKW 0x0002
223 typedef struct _object_header_t object_header_t;
226 void (*Destroy)(object_header_t*);
227 void (*CloseConnection)(object_header_t*);
228 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
229 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
230 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
231 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
232 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
233 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
234 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
235 DWORD (*FindNextFileW)(object_header_t*,void*);
238 #define INTERNET_HANDLE_IN_USE 1
240 struct _object_header_t
243 const object_vtbl_t *vtbl;
250 DWORD dwInternalFlags;
252 INTERNET_STATUS_CALLBACK lpfnStatusCB;
254 struct list children;
264 LPWSTR proxyUsername;
265 LPWSTR proxyPassword;
267 DWORD connect_timeout;
274 LPWSTR hostName; /* the final destination of the request */
277 INTERNET_PORT hostPort; /* the final destination port of the request */
278 DWORD connect_timeout;
280 DWORD receive_timeout;
283 #define HDR_ISREQUEST 0x0001
284 #define HDR_COMMADELIMITED 0x0002
285 #define HDR_SEMIDELIMITED 0x0004
293 } HTTPHEADERW, *LPHTTPHEADERW;
298 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
301 const data_stream_vtbl_t *vtbl;
305 data_stream_t data_stream;
306 DWORD content_length;
310 #define READ_BUFFER_SIZE 8192
315 http_session_t *session;
321 DWORD security_flags;
322 DWORD connect_timeout;
324 DWORD receive_timeout;
330 HTTPHEADERW *custHeaders;
332 FILETIME last_modified;
336 struct HttpAuthInfo *authInfo;
337 struct HttpAuthInfo *proxyAuthInfo;
339 CRITICAL_SECTION read_section; /* section to protect the following fields */
340 DWORD contentLength; /* total number of bytes to be read */
341 BOOL read_chunked; /* are we reading in chunked mode? */
342 BOOL read_gzip; /* are we reading in gzip mode? */
343 DWORD read_pos; /* current read position in read_buf */
344 DWORD read_size; /* valid data size in read_buf */
345 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
348 data_stream_t *data_stream;
349 netconn_stream_t netconn_stream;
354 struct WORKREQ_FTPPUTFILEW
356 LPWSTR lpszLocalFile;
357 LPWSTR lpszNewRemoteFile;
362 struct WORKREQ_FTPSETCURRENTDIRECTORYW
364 LPWSTR lpszDirectory;
367 struct WORKREQ_FTPCREATEDIRECTORYW
369 LPWSTR lpszDirectory;
372 struct WORKREQ_FTPFINDFIRSTFILEW
374 LPWSTR lpszSearchFile;
375 LPWIN32_FIND_DATAW lpFindFileData;
380 struct WORKREQ_FTPGETCURRENTDIRECTORYW
382 LPWSTR lpszDirectory;
383 DWORD *lpdwDirectory;
386 struct WORKREQ_FTPOPENFILEW
394 struct WORKREQ_FTPGETFILEW
396 LPWSTR lpszRemoteFile;
399 DWORD dwLocalFlagsAttribute;
404 struct WORKREQ_FTPDELETEFILEW
409 struct WORKREQ_FTPREMOVEDIRECTORYW
411 LPWSTR lpszDirectory;
414 struct WORKREQ_FTPRENAMEFILEW
420 struct WORKREQ_FTPFINDNEXTW
422 LPWIN32_FIND_DATAW lpFindFileData;
425 struct WORKREQ_HTTPSENDREQUESTW
428 DWORD dwHeaderLength;
430 DWORD dwOptionalLength;
431 DWORD dwContentLength;
435 struct WORKREQ_HTTPENDREQUESTW
441 struct WORKREQ_SENDCALLBACK
444 DWORD dwInternetStatus;
445 LPVOID lpvStatusInfo;
446 DWORD dwStatusInfoLength;
449 struct WORKREQ_INTERNETOPENURLW
454 DWORD dwHeadersLength;
459 struct WORKREQ_INTERNETREADFILEEXA
461 LPINTERNET_BUFFERSA lpBuffersOut;
464 struct WORKREQ_INTERNETREADFILEEXW
466 LPINTERNET_BUFFERSW lpBuffersOut;
469 typedef struct WORKREQ
471 void (*asyncproc)(struct WORKREQ*);
472 object_header_t *hdr;
475 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
476 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
477 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
478 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
479 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
480 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
481 struct WORKREQ_FTPGETFILEW FtpGetFileW;
482 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
483 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
484 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
485 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
486 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
487 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
488 struct WORKREQ_SENDCALLBACK SendCallback;
489 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
490 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
491 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
494 } WORKREQUEST, *LPWORKREQUEST;
496 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
497 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
498 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
499 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
501 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
502 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
504 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
506 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
507 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
508 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
509 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
511 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
512 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
513 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
514 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
516 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
517 struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
519 BOOL get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
520 BOOL set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
522 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
523 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
524 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest) DECLSPEC_HIDDEN;
525 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
526 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen) DECLSPEC_HIDDEN;
528 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
529 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
530 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
532 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
533 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
534 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
535 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
537 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
538 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
539 void NETCON_unload(void) DECLSPEC_HIDDEN;
540 DWORD NETCON_secure_connect(netconn_t *connection) DECLSPEC_HIDDEN;
541 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
542 int *sent /* out */) DECLSPEC_HIDDEN;
543 DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, int flags,
544 int *recvd /* out */) DECLSPEC_HIDDEN;
545 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
546 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
547 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
548 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
549 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
550 int sock_get_error(int) DECLSPEC_HIDDEN;
552 server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL);
554 BOOL init_urlcache(void) DECLSPEC_HIDDEN;
555 void free_urlcache(void) DECLSPEC_HIDDEN;
556 void free_cookie(void) DECLSPEC_HIDDEN;
558 #define MAX_REPLY_LEN 0x5B4
560 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
567 /* Undocumented security flags */
568 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
569 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
570 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
571 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
573 #define _SECURITY_ERROR_FLAGS_MASK \
574 (_SECURITY_FLAG_CERT_REV_FAILED \
575 |_SECURITY_FLAG_CERT_INVALID_CA \
576 |_SECURITY_FLAG_CERT_INVALID_CN \
577 |_SECURITY_FLAG_CERT_INVALID_DATE)
579 #endif /* _WINE_INTERNET_H_ */