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__ */
50 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
52 #ifndef INET6_ADDRSTRLEN
53 #define INET6_ADDRSTRLEN 46
59 struct sockaddr_storage addr;
61 char addr_str[INET6_ADDRSTRLEN];
67 struct list conn_pool;
70 void server_addref(server_t*) DECLSPEC_HIDDEN;
71 void server_release(server_t*) DECLSPEC_HIDDEN;
72 BOOL collect_connections(BOOL) DECLSPEC_HIDDEN;
74 /* used for netconnection.c stuff */
85 struct list pool_entry;
88 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
90 return HeapAlloc(GetProcessHeap(), 0, len);
93 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
95 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
98 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
100 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
103 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
105 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
108 static inline BOOL heap_free(void *mem)
110 return HeapFree(GetProcessHeap(), 0, mem);
113 static inline LPWSTR heap_strdupW(LPCWSTR str)
120 size = (strlenW(str)+1)*sizeof(WCHAR);
121 ret = heap_alloc(size);
123 memcpy(ret, str, size);
129 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
137 for(len=0; len<max_len; len++)
141 ret = heap_alloc(sizeof(WCHAR)*(len+1));
143 memcpy(ret, str, sizeof(WCHAR)*len);
150 static inline WCHAR *heap_strdupAtoW(const char *str)
157 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
158 ret = heap_alloc(len*sizeof(WCHAR));
160 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
166 static inline char *heap_strdupWtoA(LPCWSTR str)
171 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
172 ret = heap_alloc(size);
174 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
180 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
182 dataA->dwFileAttributes = dataW->dwFileAttributes;
183 dataA->ftCreationTime = dataW->ftCreationTime;
184 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
185 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
186 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
187 dataA->nFileSizeLow = dataW->nFileSizeLow;
188 dataA->dwReserved0 = dataW->dwReserved0;
189 dataA->dwReserved1 = dataW->dwReserved1;
190 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
191 dataA->cFileName, sizeof(dataA->cFileName),
193 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
194 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
200 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
201 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
202 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
203 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
204 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
205 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
206 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
209 #define INET_OPENURL 0x0001
210 #define INET_CALLBACKW 0x0002
212 typedef struct _object_header_t object_header_t;
215 void (*Destroy)(object_header_t*);
216 void (*CloseConnection)(object_header_t*);
217 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
218 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
219 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
220 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
221 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
222 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
223 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
224 DWORD (*FindNextFileW)(object_header_t*,void*);
227 #define INTERNET_HANDLE_IN_USE 1
229 struct _object_header_t
232 const object_vtbl_t *vtbl;
239 DWORD dwInternalFlags;
241 INTERNET_STATUS_CALLBACK lpfnStatusCB;
243 struct list children;
253 LPWSTR proxyUsername;
254 LPWSTR proxyPassword;
256 DWORD connect_timeout;
263 LPWSTR hostName; /* the final destination of the request */
264 LPWSTR serverName; /* the name of the server we directly connect to */
267 INTERNET_PORT hostPort; /* the final destination port of the request */
268 INTERNET_PORT serverPort; /* the port of the server we directly connect to */
269 DWORD connect_timeout;
271 DWORD receive_timeout;
274 #define HDR_ISREQUEST 0x0001
275 #define HDR_COMMADELIMITED 0x0002
276 #define HDR_SEMIDELIMITED 0x0004
284 } HTTPHEADERW, *LPHTTPHEADERW;
289 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
292 const data_stream_vtbl_t *vtbl;
296 data_stream_t data_stream;
297 DWORD content_length;
301 #define READ_BUFFER_SIZE 8192
306 http_session_t *session;
311 DWORD security_flags;
312 DWORD connect_timeout;
314 DWORD receive_timeout;
320 HTTPHEADERW *custHeaders;
322 FILETIME last_modified;
326 struct HttpAuthInfo *authInfo;
327 struct HttpAuthInfo *proxyAuthInfo;
329 CRITICAL_SECTION read_section; /* section to protect the following fields */
330 DWORD contentLength; /* total number of bytes to be read */
331 BOOL read_chunked; /* are we reading in chunked mode? */
332 BOOL read_gzip; /* are we reading in gzip mode? */
333 DWORD read_pos; /* current read position in read_buf */
334 DWORD read_size; /* valid data size in read_buf */
335 BYTE read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
338 data_stream_t *data_stream;
339 netconn_stream_t netconn_stream;
344 struct WORKREQ_FTPPUTFILEW
346 LPWSTR lpszLocalFile;
347 LPWSTR lpszNewRemoteFile;
352 struct WORKREQ_FTPSETCURRENTDIRECTORYW
354 LPWSTR lpszDirectory;
357 struct WORKREQ_FTPCREATEDIRECTORYW
359 LPWSTR lpszDirectory;
362 struct WORKREQ_FTPFINDFIRSTFILEW
364 LPWSTR lpszSearchFile;
365 LPWIN32_FIND_DATAW lpFindFileData;
370 struct WORKREQ_FTPGETCURRENTDIRECTORYW
372 LPWSTR lpszDirectory;
373 DWORD *lpdwDirectory;
376 struct WORKREQ_FTPOPENFILEW
384 struct WORKREQ_FTPGETFILEW
386 LPWSTR lpszRemoteFile;
389 DWORD dwLocalFlagsAttribute;
394 struct WORKREQ_FTPDELETEFILEW
399 struct WORKREQ_FTPREMOVEDIRECTORYW
401 LPWSTR lpszDirectory;
404 struct WORKREQ_FTPRENAMEFILEW
410 struct WORKREQ_FTPFINDNEXTW
412 LPWIN32_FIND_DATAW lpFindFileData;
415 struct WORKREQ_HTTPSENDREQUESTW
418 DWORD dwHeaderLength;
420 DWORD dwOptionalLength;
421 DWORD dwContentLength;
425 struct WORKREQ_HTTPENDREQUESTW
431 struct WORKREQ_SENDCALLBACK
434 DWORD dwInternetStatus;
435 LPVOID lpvStatusInfo;
436 DWORD dwStatusInfoLength;
439 struct WORKREQ_INTERNETOPENURLW
444 DWORD dwHeadersLength;
449 struct WORKREQ_INTERNETREADFILEEXA
451 LPINTERNET_BUFFERSA lpBuffersOut;
454 struct WORKREQ_INTERNETREADFILEEXW
456 LPINTERNET_BUFFERSW lpBuffersOut;
459 typedef struct WORKREQ
461 void (*asyncproc)(struct WORKREQ*);
462 object_header_t *hdr;
465 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
466 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
467 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
468 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
469 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
470 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
471 struct WORKREQ_FTPGETFILEW FtpGetFileW;
472 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
473 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
474 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
475 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
476 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
477 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
478 struct WORKREQ_SENDCALLBACK SendCallback;
479 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
480 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
481 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
484 } WORKREQUEST, *LPWORKREQUEST;
486 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t) DECLSPEC_HIDDEN;
487 object_header_t *get_handle_object( HINTERNET hinternet ) DECLSPEC_HIDDEN;
488 object_header_t *WININET_AddRef( object_header_t *info ) DECLSPEC_HIDDEN;
489 BOOL WININET_Release( object_header_t *info ) DECLSPEC_HIDDEN;
491 DWORD INET_QueryOption(object_header_t*,DWORD,void*,DWORD*,BOOL) DECLSPEC_HIDDEN;
492 DWORD INET_SetOption(object_header_t*,DWORD,void*,DWORD) DECLSPEC_HIDDEN;
494 time_t ConvertTimeString(LPCWSTR asctime) DECLSPEC_HIDDEN;
496 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
497 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
498 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
499 DWORD dwInternalFlags) DECLSPEC_HIDDEN;
501 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
502 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
503 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
504 DWORD dwInternalFlags, HINTERNET*) DECLSPEC_HIDDEN;
506 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
507 struct sockaddr *psa, socklen_t *sa_len) DECLSPEC_HIDDEN;
509 BOOL get_cookie(const WCHAR*,const WCHAR*,WCHAR*,DWORD*) DECLSPEC_HIDDEN;
510 BOOL set_cookie(const WCHAR*,const WCHAR*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
512 void INTERNET_SetLastError(DWORD dwError) DECLSPEC_HIDDEN;
513 DWORD INTERNET_GetLastError(void) DECLSPEC_HIDDEN;
514 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest) DECLSPEC_HIDDEN;
515 LPSTR INTERNET_GetResponseBuffer(void) DECLSPEC_HIDDEN;
516 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen) DECLSPEC_HIDDEN;
518 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
519 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
520 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
522 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
523 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
524 DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
525 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
527 DWORD create_netconn(BOOL, server_t *, DWORD, DWORD, netconn_t **) DECLSPEC_HIDDEN;
528 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
529 void NETCON_unload(void) DECLSPEC_HIDDEN;
530 DWORD NETCON_secure_connect(netconn_t *connection) DECLSPEC_HIDDEN;
531 DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
532 int *sent /* out */) DECLSPEC_HIDDEN;
533 DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, int flags,
534 int *recvd /* out */) DECLSPEC_HIDDEN;
535 BOOL NETCON_query_data_available(netconn_t *connection, DWORD *available) DECLSPEC_HIDDEN;
536 BOOL NETCON_is_alive(netconn_t*) DECLSPEC_HIDDEN;
537 LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN;
538 int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
539 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
540 int sock_get_error(int) DECLSPEC_HIDDEN;
542 extern void URLCacheContainers_CreateDefaults(void) DECLSPEC_HIDDEN;
543 extern void URLCacheContainers_DeleteAll(void) DECLSPEC_HIDDEN;
545 #define MAX_REPLY_LEN 0x5B4
547 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
554 #endif /* _WINE_INTERNET_H_ */