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 /* used for netconnection.c stuff */
56 } WININET_NETCONNECTION
;
58 static inline LPWSTR
WININET_strdupW( LPCWSTR str
)
60 LPWSTR ret
= HeapAlloc( GetProcessHeap(), 0, (strlenW(str
) + 1)*sizeof(WCHAR
) );
61 if (ret
) strcpyW( ret
, str
);
65 static inline LPWSTR
WININET_strdup_AtoW( LPCSTR str
)
67 int len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0);
68 LPWSTR ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
70 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
74 static inline LPSTR
WININET_strdup_WtoA( LPCWSTR str
)
76 int len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
77 LPSTR ret
= HeapAlloc( GetProcessHeap(), 0, len
);
79 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
83 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW
, LPWIN32_FIND_DATAA dataA
)
85 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
86 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
87 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
88 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
89 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
90 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
91 dataA
->dwReserved0
= dataW
->dwReserved0
;
92 dataA
->dwReserved1
= dataW
->dwReserved1
;
93 WideCharToMultiByte(CP_ACP
, 0, dataW
->cFileName
, -1,
94 dataA
->cFileName
, sizeof(dataA
->cFileName
),
96 WideCharToMultiByte(CP_ACP
, 0, dataW
->cAlternateFileName
, -1,
97 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
),
103 WH_HINIT
= INTERNET_HANDLE_TYPE_INTERNET
,
104 WH_HFTPSESSION
= INTERNET_HANDLE_TYPE_CONNECT_FTP
,
105 WH_HGOPHERSESSION
= INTERNET_HANDLE_TYPE_CONNECT_GOPHER
,
106 WH_HHTTPSESSION
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
,
107 WH_HFILE
= INTERNET_HANDLE_TYPE_FTP_FILE
,
108 WH_HFTPFINDNEXT
= INTERNET_HANDLE_TYPE_FTP_FIND
,
109 WH_HHTTPREQ
= INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
112 #define INET_OPENURL 0x0001
113 #define INET_CALLBACKW 0x0002
115 typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER
, *LPWININETHANDLEHEADER
;
118 void (*Destroy
)(WININETHANDLEHEADER
*);
119 void (*CloseConnection
)(WININETHANDLEHEADER
*);
120 DWORD (*QueryOption
)(WININETHANDLEHEADER
*,DWORD
,void*,DWORD
*,BOOL
);
121 DWORD (*SetOption
)(WININETHANDLEHEADER
*,DWORD
,void*,DWORD
);
122 DWORD (*ReadFile
)(WININETHANDLEHEADER
*,void*,DWORD
,DWORD
*);
123 DWORD (*ReadFileExA
)(WININETHANDLEHEADER
*,INTERNET_BUFFERSA
*,DWORD
,DWORD_PTR
);
124 DWORD (*ReadFileExW
)(WININETHANDLEHEADER
*,INTERNET_BUFFERSW
*,DWORD
,DWORD_PTR
);
125 BOOL (*WriteFile
)(WININETHANDLEHEADER
*,const void*,DWORD
,DWORD
*);
126 DWORD (*QueryDataAvailable
)(WININETHANDLEHEADER
*,DWORD
*,DWORD
,DWORD_PTR
);
127 DWORD (*FindNextFileW
)(WININETHANDLEHEADER
*,void*);
130 struct _WININETHANDLEHEADER
133 const HANDLEHEADERVtbl
*vtbl
;
138 DWORD dwInternalFlags
;
140 INTERNET_STATUS_CALLBACK lpfnStatusCB
;
142 struct list children
;
148 WININETHANDLEHEADER hdr
;
151 LPWSTR lpszProxyBypass
;
152 LPWSTR lpszProxyUsername
;
153 LPWSTR lpszProxyPassword
;
155 } WININETAPPINFOW
, *LPWININETAPPINFOW
;
160 WININETHANDLEHEADER hdr
;
161 WININETAPPINFOW
*lpAppInfo
;
162 LPWSTR lpszHostName
; /* the final destination of the request */
163 LPWSTR lpszServerName
; /* the name of the server we directly connect to */
166 INTERNET_PORT nHostPort
; /* the final destination port of the request */
167 INTERNET_PORT nServerPort
; /* the port of the server we directly connect to */
168 struct sockaddr_in socketAddress
;
169 } WININETHTTPSESSIONW
, *LPWININETHTTPSESSIONW
;
171 #define HDR_ISREQUEST 0x0001
172 #define HDR_COMMADELIMITED 0x0002
173 #define HDR_SEMIDELIMITED 0x0004
181 } HTTPHEADERW
, *LPHTTPHEADERW
;
186 typedef struct gzip_stream_t gzip_stream_t
;
190 WININETHANDLEHEADER hdr
;
191 WININETHTTPSESSIONW
*lpHttpSession
;
194 LPWSTR lpszRawHeaders
;
195 WININET_NETCONNECTION netConnection
;
197 LPWSTR lpszStatusText
;
198 DWORD dwBytesToWrite
;
199 DWORD dwBytesWritten
;
200 HTTPHEADERW
*pCustHeaders
;
203 LPWSTR lpszCacheFile
;
204 struct HttpAuthInfo
*pAuthInfo
;
205 struct HttpAuthInfo
*pProxyAuthInfo
;
207 CRITICAL_SECTION read_section
; /* section to protect the following fields */
208 DWORD dwContentLength
; /* total number of bytes to be read */
209 DWORD dwContentRead
; /* bytes of the content read so far */
210 BOOL read_chunked
; /* are we reading in chunked mode? */
211 DWORD read_pos
; /* current read position in read_buf */
212 DWORD read_size
; /* valid data size in read_buf */
213 BYTE read_buf
[4096]; /* buffer for already read but not returned data */
216 gzip_stream_t
*gzip_stream
;
217 } WININETHTTPREQW
, *LPWININETHTTPREQW
;
221 struct WORKREQ_FTPPUTFILEW
223 LPWSTR lpszLocalFile
;
224 LPWSTR lpszNewRemoteFile
;
229 struct WORKREQ_FTPSETCURRENTDIRECTORYW
231 LPWSTR lpszDirectory
;
234 struct WORKREQ_FTPCREATEDIRECTORYW
236 LPWSTR lpszDirectory
;
239 struct WORKREQ_FTPFINDFIRSTFILEW
241 LPWSTR lpszSearchFile
;
242 LPWIN32_FIND_DATAW lpFindFileData
;
247 struct WORKREQ_FTPGETCURRENTDIRECTORYW
249 LPWSTR lpszDirectory
;
250 DWORD
*lpdwDirectory
;
253 struct WORKREQ_FTPOPENFILEW
261 struct WORKREQ_FTPGETFILEW
263 LPWSTR lpszRemoteFile
;
266 DWORD dwLocalFlagsAttribute
;
271 struct WORKREQ_FTPDELETEFILEW
276 struct WORKREQ_FTPREMOVEDIRECTORYW
278 LPWSTR lpszDirectory
;
281 struct WORKREQ_FTPRENAMEFILEW
287 struct WORKREQ_FTPFINDNEXTW
289 LPWIN32_FIND_DATAW lpFindFileData
;
292 struct WORKREQ_HTTPSENDREQUESTW
295 DWORD dwHeaderLength
;
297 DWORD dwOptionalLength
;
298 DWORD dwContentLength
;
302 struct WORKREQ_HTTPENDREQUESTW
308 struct WORKREQ_SENDCALLBACK
311 DWORD dwInternetStatus
;
312 LPVOID lpvStatusInfo
;
313 DWORD dwStatusInfoLength
;
316 struct WORKREQ_INTERNETOPENURLW
321 DWORD dwHeadersLength
;
326 struct WORKREQ_INTERNETREADFILEEXA
328 LPINTERNET_BUFFERSA lpBuffersOut
;
331 struct WORKREQ_INTERNETREADFILEEXW
333 LPINTERNET_BUFFERSW lpBuffersOut
;
336 typedef struct WORKREQ
338 void (*asyncproc
)(struct WORKREQ
*);
339 WININETHANDLEHEADER
*hdr
;
342 struct WORKREQ_FTPPUTFILEW FtpPutFileW
;
343 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW
;
344 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW
;
345 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW
;
346 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW
;
347 struct WORKREQ_FTPOPENFILEW FtpOpenFileW
;
348 struct WORKREQ_FTPGETFILEW FtpGetFileW
;
349 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW
;
350 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW
;
351 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW
;
352 struct WORKREQ_FTPFINDNEXTW FtpFindNextW
;
353 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW
;
354 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW
;
355 struct WORKREQ_SENDCALLBACK SendCallback
;
356 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW
;
357 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA
;
358 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW
;
361 } WORKREQUEST
, *LPWORKREQUEST
;
363 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
);
364 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
);
365 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
);
366 BOOL
WININET_Release( LPWININETHANDLEHEADER info
);
367 BOOL
WININET_FreeHandle( HINTERNET hinternet
);
369 DWORD
INET_QueryOption(DWORD
,void*,DWORD
*,BOOL
);
371 time_t ConvertTimeString(LPCWSTR asctime
);
373 HINTERNET
FTP_Connect(LPWININETAPPINFOW hIC
, LPCWSTR lpszServerName
,
374 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
375 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
376 DWORD dwInternalFlags
);
378 HINTERNET
HTTP_Connect(LPWININETAPPINFOW hIC
, LPCWSTR lpszServerName
,
379 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
380 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
381 DWORD dwInternalFlags
);
383 BOOL
GetAddress(LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
384 struct sockaddr_in
*psa
);
386 void INTERNET_SetLastError(DWORD dwError
);
387 DWORD
INTERNET_GetLastError(void);
388 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
);
389 LPSTR
INTERNET_GetResponseBuffer(void);
390 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
);
392 BOOLAPI
HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszHeaders
,
393 DWORD dwHeaderLength
, LPVOID lpOptional
, DWORD dwOptionalLength
,
394 DWORD dwContentLength
, BOOL bEndRequest
);
395 INTERNETAPI HINTERNET WINAPI
HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs
,
396 LPCWSTR lpszVerb
, LPCWSTR lpszObjectName
, LPCWSTR lpszVersion
,
397 LPCWSTR lpszReferrer
, LPCWSTR
*lpszAcceptTypes
,
398 DWORD dwFlags
, DWORD_PTR dwContext
);
400 VOID
SendAsyncCallback(LPWININETHANDLEHEADER hdr
, DWORD_PTR dwContext
,
401 DWORD dwInternetStatus
, LPVOID lpvStatusInfo
,
402 DWORD dwStatusInfoLength
);
404 VOID
INTERNET_SendCallback(LPWININETHANDLEHEADER hdr
, DWORD_PTR dwContext
,
405 DWORD dwInternetStatus
, LPVOID lpvStatusInfo
,
406 DWORD dwStatusInfoLength
);
408 BOOL
NETCON_connected(WININET_NETCONNECTION
*connection
);
409 BOOL
NETCON_init(WININET_NETCONNECTION
*connnection
, BOOL useSSL
);
410 BOOL
NETCON_create(WININET_NETCONNECTION
*connection
, int domain
,
411 int type
, int protocol
);
412 BOOL
NETCON_close(WININET_NETCONNECTION
*connection
);
413 BOOL
NETCON_connect(WININET_NETCONNECTION
*connection
, const struct sockaddr
*serv_addr
,
414 unsigned int addrlen
);
415 BOOL
NETCON_secure_connect(WININET_NETCONNECTION
*connection
, LPCWSTR hostname
);
416 BOOL
NETCON_send(WININET_NETCONNECTION
*connection
, const void *msg
, size_t len
, int flags
,
417 int *sent
/* out */);
418 BOOL
NETCON_recv(WININET_NETCONNECTION
*connection
, void *buf
, size_t len
, int flags
,
419 int *recvd
/* out */);
420 BOOL
NETCON_query_data_available(WININET_NETCONNECTION
*connection
, DWORD
*available
);
421 LPCVOID
NETCON_GetCert(WININET_NETCONNECTION
*connection
);
422 DWORD
NETCON_set_timeout(WININET_NETCONNECTION
*connection
, BOOL send
, int value
);
424 extern void URLCacheContainers_CreateDefaults(void);
425 extern void URLCacheContainers_DeleteAll(void);
427 #define MAX_REPLY_LEN 0x5B4
429 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
436 #endif /* _WINE_INTERNET_H_ */